Results 1 to 2 of 2

Thread: Insert into Linked Access Using ADO.Net

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    Fort Lauderdale, FL
    Posts
    98

    Insert into Linked Access Using ADO.Net

    OK, I keep getting a syntax error on insert. But the statement is fine, (I think). Can anybody help???




    Dim myCommand As New OleDb.OleDbCommand()
    Dim myTrans As OleDb.OleDbTransaction

    Dim myConnection As OleDb.OleDbConnection
    Dim sConnString As String
    Dim sSQL as String

    sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:\City1.mdb;"


    sSQL = "insert into Real_Estate (real_estate, subdivision, land_district,Block, Lot,range,section,township) values ('" & rsEDI.Fields(0).Value & "','" & rsEDI.Fields(1).Value & "','" & rsEDI.Fields(2).Value & "','" & rsEDI.Fields(3).Value & "','" & rsEDI.Fields(4).Value & "','" & rsEDI.Fields(5).Value & "','" & rsEDI.Fields(6).Value & "','" & rsEDI.Fields(7).Value & "')"


    myConnection = New OleDb.OleDbConnection(sConnString)
    myConnection.Open()


    myCommand.Connection = myConnection

    myTrans = myConnection.BeginTransaction()

    myCommand.Transaction = myTrans

    Try

    myCommand.CommandText = sSQL
    myCommand.ExecuteNonQuery()
    myTrans.Commit()

    Catch i As Exception
    MsgBox(Err.Description)
    Finally
    myConnection.Close()
    End Try

  2. #2
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    Try something like this...

    Dim SQL as string = "INSERT INTO myTable (MyField) VALUES (@myValue)"

    Dim dc As SqlConnection
    Dim sc As SqlCommand

    dc = New SqlConnection(myConnectionString)
    sc = New SqlCommand(SQL, dc)
    sc.Parameters.Add(New SqlParameter("@myValue", myValue))
    dc.Open()
    Return sc.ExecuteNonQuery
    That which does not kill us, only makes us stronger.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width