Вопрос

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

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top