You should use a Command Builder to update records so that changes made to the dataset can be reflected into the database. Here is some sample code-
Public Class Form1
Dim cn As New Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=shreyas; User=root;Password=;")
Dim cmd As Odbc.OdbcCommand
Dim adp As Odbc.OdbcDataAdapter
Dim ds As New DataSet
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
cn.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Fill the data grid viewer
cn.Open()
cmd = New Odbc.OdbcCommand("Select * from trial1", cn)
adp = New Odbc.OdbcDataAdapter(cmd)
adp.Fill(ds, "trial1")
Me.DataGridView1.DataSource = ds
Me.DataGridView1.DataMember = "trial1"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Update records using a Command Builder
' The variable i gives the number of records updated
Dim cmdbuilder As New Odbc.OdbcCommandBuilder(adp)
Dim i As Integer
Try
i = adp.Update(ds, "trial1")
MsgBox("Records Updated= " & i)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class