我正在尝试使用SqlDataAdapter
更新数据库,但我的代码似乎不起作用:
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)
据我所知,代码似乎没问题,有人有任何建议吗?
由于
答案 0 :(得分:3)
删除dt.AcceptChanges
,它应该有用。
AcceptChanges
会将RowState
更改为Unchanged
,这会导致DataAdapter
无效。更新后AcceptChanges
本身会隐含地调用DataAdapter
。