Public Class frmMember
Dim Conn As SqlConnection
Dim Cmd As SqlCommand
Dim ds As New DataSet
Dim ad As New SqlDataAdapter
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
If DataGridView1.SelectedRows.Count = 0 Then
MessageBox.Show("ท่านยังไม่ได้เลือกแถวที่ต้องการลบ")
Exit Sub
End If
Dim msgResult As DialogResult = MessageBox.Show("ท่านต้องการลบข้อมูลแถวที่เลือกจริงหรือไม่", "ยืนยันการลบ", MessageBoxButtons.OKCancel)
If msgResult = Windows.Forms.DialogResult.Cancel Then
Exit Sub
End If
Conn.Open()
Dim Key As String = DataGridView1.SelectedRows.Item(0).Cells(0).Value
Dim sql As String = " DELETE FORM TblMember WHERE MemberID = " & Key
Dim cmd As New SqlCommand(sql, Conn)
Cmd.CommandText = sql
cmd.ExecuteNonQuery()
End Sub
End Class