'//////////ปุ่ม delete ใน datagrid/////////////
If dgvAgent.Columns(e.ColumnIndex).HeaderText = "Delete" AndAlso Me.dgvAgent.Rows(e.RowIndex).IsNewRow = False Then
Dim sqlDelete As String
Dim comAdd As New OleDbCommand
If tbxName.Text = "" Then
MessageBox.Show("กรุณาเลือกข้อมูลที่ต้องการลบ", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
dgvAgent.Focus()
End If
If MessageBox.Show("ต้องการลบข้อมูล", "ยืนยันการลบ", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
Dim success As Boolean = True
Dim errorMessage As String = String.Empty
Conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Database passport\Passport.accdb;")
Conn.Open()
sqlDelete = " DELETE From Agent "
sqlDelete &= " WHERE (Agent_ID=" & tbxAgent_ID.Text & ")"
Dim cmd As New OleDbCommand(sqlDelete, Conn)
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlDelete
.Connection = Conn
.ExecuteNonQuery()
End With
Try
'comAdd.ExecuteNonQuery()
Catch ex As Exception
success = False
errorMessage = ex.Message
End Try
' Me.dgvAgent.Rows.RemoveAt(e.RowIndex)
Conn.Close()
MessageBox.Show("ลบข้อมูลเรียบร้อยแล้ว")
Me.Hide()
Dim f As New AgentForm
f.Show()
End If
End If