Could not save changes to DataGridView1 in DB
When a form is opened, it contains a filled table in DataGridView1 At the same time, the all InsertCommand properties are empty in the from_load variable DA ... When you close the form, all the InsertCommand commands to DA are empty I tried to set them again - no result - the changes are not transferred to the database
There is a form
Public Class frmStatus Public DA As OdbcDataAdapter Public DS As DataSet Private Sub frmStatus_Closed(sender As Object, e As EventArgs) Handles Me.Closed 'DA.SelectCommand = New OdbcCommand("SELECT id,name FROM status") 'DA.InsertCommand = New OdbcCommand("INSERT INTO status ( name) VALUES (?)") 'DA.UpdateCommand = New OdbcCommand("UPDATE status SET name = ? WHERE id = ?") 'DA.DeleteCommand = New OdbcCommand("DELETE FROM status WHERE id = ?") DA.Update(DS, "table") DS.Tables("table").AcceptChanges() End Sub Private Sub frmStatus_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class I call the form, passing it the parameters
Dim frmM As New frmStatus 'frmM = New frmStatus() Dim Sql As String = "SELECT id,name FROM status" Dim InsertCommand = "INSERT INTO status ( name) VALUES (?)" Dim UpdateCommand = "UPDATE status SET name = ? WHERE id = ?" Dim DeleteCommand = "DELETE FROM status WHERE id = ?" frmM.DA = New OdbcDataAdapter frmM.DS = New DataSet Add_Connect_updated(frmM.DataGridView1, frmM.DA, frmM.DS, Sql, InsertCommand, UpdateCommand, DeleteCommand) frmM.ShowDialog() Add_Connect_updated code:
Dim MyConString As String = StringConnectToBDMySQL(driver_mysql, options_server, options_database, options_user, options_password, "3") DA = New OdbcDataAdapter(strSQL, MyConString) DA.MissingMappingAction = MissingMappingAction.Passthrough DA.MissingSchemaAction = MissingSchemaAction.AddWithKey DA.Fill(DS, "table") Dim dbCommandBuilder As New OdbcCommandBuilder(DA) DA.InsertCommand = dbCommandBuilder.GetInsertCommand() DA.UpdateCommand = dbCommandBuilder.GetUpdateCommand() DA.DeleteCommand = dbCommandBuilder.GetDeleteCommand() ObjectDataSource.DataSource = DS.Tables("table")