problem to insert data in access

  • 13 years ago

    hello!!!

    i want a proplem with my insertion from vb.net to access.

    i try to write:

    sql = "insert into mydata('field1, field2,...) values (cbxname.selectvalue, cbxnum.selectvalue,....)

    i can see the insertion put with null result.... i cant see the values that i put only insertion with not values.

    how can i resolve this problem.

    pls help me

    thanx in advance

  • 13 years ago
    try like this .........
    sql = "insert into mydata(field1, field2,...) values ("+cbxname.selectvalue+","+ cbxnum.selectvalue+","+....)
  • 13 years ago

    Hey Pantel i have a small idea .

    u just use procedure below:

    Imports

    System.Data.OleDb

    Imports

    System.IO

    Dim

    cnn As New OleDb.OleDbConnection

    Sub DBConnection(ByVal PTH As String)

    Try

    cnn =

    New OleDbConnection("Provider=microsoft.jet.oledb.4.0; data source='" & PTH & "'")

    cnn.Open()

    Catch ex As Exception

    MsgBox(ex.Message, MsgBoxStyle.Information,

    "")

    End

    End Try

    End Sub

    Sub AddNewRecord(ByVal tbl As String, ByVal ParamArray Data() As String)

    Dim cm As New OleDb.OleDbCommand()

    Dim da As New OleDb.OleDbDataAdapter()

    Dim ds As New DataSet()

    Dim Temp As String

    Dim FTemp As String

    Try

    ds =

    New DataSet(tbl)

    da =

    New OleDb.OleDbDataAdapter("select * from " & tbl, cnn)

    da.Fill(ds, tbl)

    Dim i As Integer

    For i = 0 To UBound(Data)

    Dim fieldName = ds.Tables(tbl).Columns(i).ColumnName ' find caption of field name

    Temp = Temp & fieldName &

    ","

    FTemp = FTemp &

    "'" & Data(i) & "'" & ","

    Next

    Temp = Strings.Left(Temp, Len(Temp) - 1)

    FTemp = Strings.Left(FTemp, Len(FTemp) - 1)

    Dim sql As String

    sql =

    "Insert into " & tbl & "(" & Temp & ")" & " Values(" & FTemp & ")"

    cm.CommandText = sql

    cm.Connection = cnn

    cm.ExecuteNonQuery()

    Catch ex As Exception

    MsgBox(ex.Message)

    End Try

    End Sub

    'Calling Procedure

    AddNewRecord(

    "Productinfo", TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text)

    Sorry if Something  not the same your mind.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.” - Jon Ribbens