problem to insert data in access

  • 13 years ago


    i want a proplem with my insertion from 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:






    cnn As New OleDb.OleDbConnection

    Sub DBConnection(ByVal PTH As String)


    cnn =

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


    Catch ex As Exception

    MsgBox(ex.Message, MsgBoxStyle.Information,



    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


    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) & "'" & ","


    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


    Catch ex As Exception


    End Try

    End Sub

    'Calling Procedure


    "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).


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.

“A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila” - Mitch Ratcliffe