Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
If MessageBox.Show("คุณต้องการลบข้อมูลนี้ใช่หรือไม่ ?", "ยืนยันการลบ", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
Dim strID As String = Me.dgv(0, Me.dgv.CurrentCell.RowIndex).Value.ToString()
Dim i As Integer = 0
For i = 0 To dgv.SelectedRows.Count - 1
dgv.Rows.Remove(dgv.SelectedRows(0))
Next
Dim myConnection As OdbcConnection = New OdbcConnection
myConnection.ConnectionString = myConStr
myConnection.Open()
Dim myCommand As Data.Odbc.OdbcCommand = myConnection.CreateCommand()
myCommand.CommandText = "DELETE FROM [TB2006] WHERE idya = '" & strID & "'"
myCommand.CommandType = CommandType.Text
myCommand.ExecuteNonQuery()
myConnection.Close()
MessageBox.Show("ลบข้อมูลเรียบร้อยแล้ว", "ระบบตรวจสอบ")
dgv.Refresh()
End If
End Sub