Doing an Update query using Dataadapter

Needed an expert to tell me if I am on the right track for doing an update query to change a field in an Access table using OLEDB.

Here is the code I think would work. I know how to do in under ADO Classic in VB6 but know things are different now.

Dim DaMain As New OleDbDataAdapter

Dim DtMain As New DataTable

Dim sql As String = "update [" & SourceDatabase * "] Set [" & FieldName & "] = " & RecordID & " where [" & FieldName & "] = " & OldRecordID

DaMain.SelectCommand = New OleDbCommand(sql, CountySourceConnection)

DaMain.Update(DtMain)

Thanks

Larry Gatlin



Answer this question

Doing an Update query using Dataadapter

  • Avi_harush

    Great! Thank you. I knew there had to be a better solution than what I was doing. That solves a bunch of headaches!

    Larry


  • MikeHNatti

    Use an OleDB command to update the database like that



    Dim sql As String = "update [" & SourceDatabase & "] Set [" & FieldName & "] = " & RecordID & " where [" & FieldName & "] = " & OldRecordID
    Dim cmdMain As New OleDbCommand(sql, CountySourceConnection)
    CountySourceConnection.Open
    cmdMain.ExecuteNonQuery
    CountySourceConnection.Close




  • Doing an Update query using Dataadapter