I want to update data using DataGridView in Visual Studio2008 with the following code. But it is not working. Plz help me.

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
cmd = New Odbc.OdbcCommand("UPDATE Table1 SET Name")
Me.Table1TableAdapter.Update(DataSet1.Table1)
MsgBox("Updated")
End Sub

Recommended Answers

All 2 Replies

your command and table adapter are not associated.

I want to update data using DataGridView in Visual Studio2008 with the following code. But it is not working. Plz help me.

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
cmd = New Odbc.OdbcCommand("UPDATE Table1 SET Name")
Me.Table1TableAdapter.Update(DataSet1.Table1)
MsgBox("Updated")
End Sub

i'll give you an example how to Update in VB.NET

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
       Dim conn As New Odbc.OdbcConnection("Your Strings Here")
       conn.Open()
       Dim da As New Odbc.OdbcDataAdapter("SELECT * FROM yourTable WHERE Field1 = MyText", conn)
       Dim ds As New DataSet
       Dim cb As New Odbc.OdbcCommandBuilder(da)
       da.Fill(ds)
    
          If ds.Tables(0).Rows.Count = 1 Then
              da.Update(ds)
          MsgBox("Updated")
           End If
     
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.