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 DaMainAsNew OleDbDataAdapter

Dim DtMainAsNew DataTable

Dim sqlAsString ="update [" & SourceDatabase *"] Set [" & FieldName &"] = " & RecordID &" where [" & FieldName &"] = " & OldRecordID

DaMain.SelectCommand =New OleDbCommand(sql, CountySourceConnection)

DaMain.Update(DtMain)

Thanks

Larry Gatlin

[1558 byte] By [LarryGatlin] at [2007-12-24]
# 1

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


KenTucker at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

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

Larry

LarryGatlin at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...