Reputation: 775
I'm trying to update a database using the SqlDataAdapter
but my code does not seem to work:
Dim sitedb As String = BookingApp.Globals.siteDB
Dim conn As New SqlConnection(sitedb)
Dim sql As String = "select * from name where BOOKING_REF = 'H2124'"
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim cb As SqlCommandBuilder
Dim dt As New DataTable
Dim c As Integer
cmd = New SqlCommand(sql, conn)
da = New SqlDataAdapter(cmd)
cb = New SqlCommandBuilder(da)
da.Fill(dt)
For c = 0 To dt.Rows.Count - 1
dt.Rows(c)!OVLREF3 = c
dt.AcceptChanges()
Next
da.Update(dt)
As far as I can see the code seems to look okay, anyone got any suggestions?
Thanks
Upvotes: 0
Views: 304
Reputation: 460018
Remove dt.AcceptChanges
and it should work.
AcceptChanges
will change the RowState
to Unchanged
, that causes the DataAdapter
to do nothing. AcceptChanges
is called implicitely by the DataAdapter
itself after the update.
Upvotes: 3