Table table1 must have a primary key.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
You have to split your code into two Sub (function).
.....
Dim MyCommand1 As New MySql.Data.MySqlClient.MySqlCommand
Dim Myadapter As New MySql.Data.MySqlClient.MySqlDataAdapter
Dim MyBuilder As MySql.Data.MySqlClient.MySqlCommandBuilder
Dim MyDataTable As New DataTable
DIM MyDataset As Dataset
Private Sub Form1_Load(...)
MyCommand1.CommandText = "select * from Table1"
MyCommand1.Connection = conn
Myadapter.SelectCommand = MyCommand
Mybuilder=new MySql.Data.MySqlClient.MySqlCommandBuilder(Myadapter)
Myadapter.Fill(MydataSet,"Table1")
MyDataTable = MyDataSet.Tables("Table1")
DataGridView1.DataSource = MyDatatable
End Sub
private Sub Button1_Click(....)
If MydataSet.GetChanges() Is Nothing Then
MessageBox.Show("The table contains no changes to save.")
Else
Dim rowsAffected As Integer = Myadapter.Update(MyDatatable)
If rowsAffected = 0 Then
MessageBox.Show("No rows were affected by the save operation.")
Else
MessageBox.Show(rowsAffected & " rows were affected by the save operation.")
End If
End If
End Sub
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241