19-06-13, 11:09 PM
في الـfrmmain، وفي حدث النقر للزر حذف نكتب ما يلي:
وفيه يتم عرض رسالة تنبيه للمستخدم بأنه على وشك حذف سجل، فإن وافق يتم حذف وتحديث القائمة.
كود :
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim RecID As Integer
Dim Answer As Integer
RecID = Val(dgvList.SelectedRows(0).Cells(0).Value)
If RecID = Nothing Then
MsgBox("لم تقم باختيار سجل لحذفه", MsgBoxStyle.Critical, "عذراً")
Else
Answer = MsgBox("هل تريد فعلاً حذف هذا السجل", MsgBoxStyle.Question + MsgBoxStyle.OkCancel, "تنبيه")
If Answer = MsgBoxResult.Ok Then
Dim DelSQl As String = "DELETE * FROM TheTable WHERE ID=" & RecID & ""
Dim DelCMD As New OleDbCommand
If Con.State = ConnectionState.Closed Then
Con.Open()
With DelCMD
.Connection = Con
.CommandType = CommandType.Text
.CommandText = DelSQl
.ExecuteNonQuery()
.Dispose()
End With
Con.Close()
LoadData()
Else
With DelCMD
.Connection = Con
.CommandType = CommandType.Text
.CommandText = DelSQl
.ExecuteNonQuery()
.Dispose()
End With
Con.Close()
LoadData()
End If
End If
End If
End Subوفيه يتم عرض رسالة تنبيه للمستخدم بأنه على وشك حذف سجل، فإن وافق يتم حذف وتحديث القائمة.

