jim@firstbankms.com
New member
- Joined
- Aug 24, 2009
- Messages
- 2
- Programming Experience
- 3-5
I am using VS2012 with a vb.net Windows application. I load a datagridview with a sql database.
I have a sub that will detect the del key if the datagridview row is highlighted and will execute an tableadapter update and the record will disipear from the DGV but not the SQL database. I have another sub fired by a button that when I hit the button, it will delete. The button and the del do the same update function..
Here is the del sub
Private Sub dgvUtility_KeyDown(sender As Object, e As KeyEventArgs) Handles dgvUtility.KeyDown
Dim selectedRowCount As Integer = _
dgvUtility.Rows.GetRowCount(DataGridViewElementStates.Selected)
If selectedRowCount > 0 Then
If e.KeyCode = Keys.Delete Then
If MessageBox.Show("Are you sure you want to delete this selected record?", "Delete this record", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
' This completes the deletion
myUtilityDetailTableAdapter.Update(TellerApp2000SQLDataSet.UtilityDetail)
End If
End If
Else
MessageBox.Show("You must select the row header (Entire row) to delete", "Did you selcet the row header?")
End If
End Sub
Firing this sub alone will not delete the record from SQL. Firing this sub then clicking the Update button sub
Private Sub btUpdateUtility_Click(sender As Object, e As EventArgs) Handles btUpdateUtility.Click
myUtilityDetailTableAdapter.Update(TellerApp2000SQLDataSet.UtilityDetail)
End Sub
will successfully delete the record. Both call the same myUtilityDetailTableAdapter.Update(TellerApp2000SQLDataSet.UtilityDetail)
My question is why doesn't the first sub delete the record?
I have a sub that will detect the del key if the datagridview row is highlighted and will execute an tableadapter update and the record will disipear from the DGV but not the SQL database. I have another sub fired by a button that when I hit the button, it will delete. The button and the del do the same update function..
Here is the del sub
Private Sub dgvUtility_KeyDown(sender As Object, e As KeyEventArgs) Handles dgvUtility.KeyDown
Dim selectedRowCount As Integer = _
dgvUtility.Rows.GetRowCount(DataGridViewElementStates.Selected)
If selectedRowCount > 0 Then
If e.KeyCode = Keys.Delete Then
If MessageBox.Show("Are you sure you want to delete this selected record?", "Delete this record", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
' This completes the deletion
myUtilityDetailTableAdapter.Update(TellerApp2000SQLDataSet.UtilityDetail)
End If
End If
Else
MessageBox.Show("You must select the row header (Entire row) to delete", "Did you selcet the row header?")
End If
End Sub
Firing this sub alone will not delete the record from SQL. Firing this sub then clicking the Update button sub
Private Sub btUpdateUtility_Click(sender As Object, e As EventArgs) Handles btUpdateUtility.Click
myUtilityDetailTableAdapter.Update(TellerApp2000SQLDataSet.UtilityDetail)
End Sub
will successfully delete the record. Both call the same myUtilityDetailTableAdapter.Update(TellerApp2000SQLDataSet.UtilityDetail)
My question is why doesn't the first sub delete the record?