Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


MySqlCommandBuilder not generating update command for DataAdapter


MySqlCommandBuilder not generating update command for DataAdapter

Author
Message
Jens1970
Jens1970
Forum God
Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)Forum God (305 reputation)

Group: Forum Members
Posts: 1, Visits: 5
Hi All,



I am trying to update mysql Database with changes made by user in a windows form which contains fields bound to a table in a dataSet.

I have a first form which contains a list of employees (readonly). When the user click on a given row, the details of the corresponding employee are displayed in a second form where the user can modify the data. My problem is that when attempting to update the database through the DataAdapetr update command, nothing happen. it seems that the commandBuilder object doesn't generate the update command !

Below is the vb.net code i use. Please advise me about how to fix it : (Should i add a call for EndEdit() method for each field in the form before calling the DataAdapter update method ? how to do that ? is there a way to call such a method only one time for the entire form ?)



Thanks a lot for any help because i am really confused about this.



Best Regards.



Jens1970



Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

If (e.RowIndex <> -1) Then

Dim iRow As Integer = e.RowIndex

Dim sCurrentMatricule As String = DataGridView1.Item(0, iRow).Value.ToString

Dim CurrentEmployee As New FrmNouveauSalarie()



Dim sqlConn As MySqlConnection = New MySqlConnection(ConnectionString)

Dim sqlCmd As String = "SELECT * FROM personnel WHERE `Matricule` = " + "'" + sCurrentMatricule + "'"





Try

CurrentEmployee.empDs = New DataSet()



sqlConn.Open()

CurrentEmployee.empDa = New MySqlDataAdapter(sqlCmd, sqlConn)

CurrentEmployee.empDa.Fill(CurrentEmployee.empDs, "personnel")

sqlConn.Close()



CurrentEmployee.tbxMatricule.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "Matricule")

CurrentEmployee.tbxNom.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "Nom")

CurrentEmployee.tbxPrenom.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "Prenom")

CurrentEmployee.dtDateNaissance.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "DateNaissance")

CurrentEmployee.dtDateRecrutement.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "DateRecrutement")

CurrentEmployee.cmbSexe.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "Sexe")

CurrentEmployee.tbxNni.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "Nni")

CurrentEmployee.tbxNss.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "Nss")

CurrentEmployee.tbxTelB1.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "TelBureauExt")

CurrentEmployee.tbxTelB2.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "TelBureauInt")

CurrentEmployee.tbxTelM.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "TelMobile")

CurrentEmployee.tbxAdresse.DataBindings.Add("Text", CurrentEmployee.empDs.Tables("personnel"), "Adresse")



CurrentEmployee.ShowDialog()

Catch ex As Exception

MessageBox.Show("impossible to connect to DB : " & ex.Message)

Finally

MysqlConn.Dispose()



End Try



End If



End Sub



Code for the updateButton:





Private Sub UpdateBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btMiseAjour.Click

Dim sqlConn As MySqlConnection = New MySqlConnection(ConnectionString)







Try



sqlConn.Open()

Dim MyDataCommanBuilder As MySqlCommandBuilder = New MySqlCommandBuilder(Me.empDa)

Me.Validate()



Me.empDa.Update(Me.empDs, "personnel")

sqlConn.Close()

Catch ex As Exception

MessageBox.Show("impossible to connect to DB : " & ex.Message)

Finally

sqlConn.Dispose()



End Try



Me.Close()



End Sub

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search