Hello,
In my project when i dynamically create a DataGridView I am adding a Handler to the CellParsing event wit the following line:
My code in the Sub Routine Datgr_End_Update is an update command that updates my database when a value in the DataGridView is changed by the user.
However when I edit a value in my DataGridView the code runs, and the MsgBox pops up but the database doesn't get updated.
The strange thing is that when i put the code behind a button the code works perfectly and the database is updated :confused:
Am I creating the Handler correctly? I think that i am as when the cell value has changed the code in the Sub Routine runs, but why doesn't my database get updated?
Thank you for your time!!!
In my project when i dynamically create a DataGridView I am adding a Handler to the CellParsing event wit the following line:
Code:
AddHandler DatGr.CellParsing, (AddressOf Datgr_End_Update)
Code:
Private Sub Datgr_End_Update(sender As System.Object, e As System.EventArgs)
Dim tc_1 As TabControl
Dim dg_1 As New DataGridView
For Each Ctrl_1 As Control In tcTest.SelectedTab.Controls
If TypeOf Ctrl_1 Is TabControl Then
tc_1 = Ctrl_1
For Each Ctrl_2 As Control In tc_1.SelectedTab.Controls
If TypeOf Ctrl_2 Is DataGridView Then
dg_1 = Ctrl_2
sql = "UPDATE Skills SET empno=@empno,prod=@prod,subassy=@subassy,opno=@opno,competence=@competence" _
& ",DateAchieved=@DateAchieved,Stage=@stage Where OpNo = @opno"
Dim row As DataGridViewRow = dg_1.CurrentRow
da.UpdateCommand = New OleDbCommand(sql, con)
da.UpdateCommand.Parameters.AddWithValue("@empno", row.Cells("empno").Value)
da.UpdateCommand.Parameters.AddWithValue("@prod", row.Cells("prod").Value)
da.UpdateCommand.Parameters.AddWithValue("@subassy", row.Cells("subassy").Value)
da.UpdateCommand.Parameters.AddWithValue("@opno", row.Cells("opno").Value)
da.UpdateCommand.Parameters.AddWithValue("@competence", row.Cells("competence").Value)
da.UpdateCommand.Parameters.AddWithValue("@DateAchieved", row.Cells("DateAchieved").Value)
da.UpdateCommand.Parameters.AddWithValue("@Stage", row.Cells("stage").Value)
da.Update(ds.Tables("" & SubAss & " " & EmpNumber & ""))
MsgBox("Record has been updated")
End If
Next
End If
Next
End Sub
The strange thing is that when i put the code behind a button the code works perfectly and the database is updated :confused:
Am I creating the Handler correctly? I think that i am as when the cell value has changed the code in the Sub Routine runs, but why doesn't my database get updated?
Thank you for your time!!!