0

我正在尝试使用更新数据库,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)

据我所见,代码看起来还不错,有人有什么建议吗?

谢谢

4

1 回答 1

3

删除dt.AcceptChanges它应该可以工作。

AcceptChanges将改变RowStateto Unchanged,这会导致DataAdapterto 什么也不做。更新后由自身AcceptChanges隐式调用。DataAdapter

于 2013-07-22T13:01:42.300 回答