2

我正在从 SQL Server 2008 数据库表中填充 DataGridView。然后我允许用户编辑 DataGridView 中的值,我正在努力的是如何在按下按钮时将这些更改写回 SQL 表?

我正在使用这个填充:

 Try

            Dim command As New SqlCommand
            Dim adapter As New SqlDataAdapter

            DutyRef = DutyRef.Trim
            Dim DutyDetails As String = "SELECT * from MyTable WHERE Col1 = 1"


            If ds1.Tables("DT_Test").Rows.Count > 0 Then
                ds1.Tables("DT_Test").Rows.Clear()
                Tab2_DGVDuty.Refresh()
            End If

            SQLConn = New SqlConnection(SQLConnString)

            command = New SqlCommand(DutyDetails, SQLConn)
            adapter.SelectCommand = command
            adapter.Fill(ds1, "DT_Test")

            Tab2_DGVDuty.DataSource = ds1.Tables("DT_Test")
            Tab2_DGVDuty.Columns("ID").Visible = False


            adapter.Dispose()
            command.Dispose()
            SQLConn.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
4

1 回答 1

2

看一眼SqlDataAdapter.Update

本文可能对您有所帮助:如何在 Visual Basic .NET 中使用 SqlDataAdapter 对象更新 SQL Server 数据库

于 2013-02-12T11:16:13.137 回答