2

I am populating a DataGridView from a SQL Server 2008 database table. I then allow users to edit the values in the DataGridView, what I am struggling on is how to then write these changes back to the SQL table on a button press?

I am populating using this:

 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

1 Answer 1

2

Take a look at SqlDataAdapter.Update

This article may help you: How To Update a SQL Server Database by Using the SqlDataAdapter Object in Visual Basic .NET

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.