delete the highlighted row
ADODC
DATAGRID
MYSQL

Try this.....

Dim conn As New ADODB.Connection
Dim rec As New ADODB.Recordset

Private Sub cmd_delete_Click()
   Dim rResult
   
   rResult = MsgBox("Do you want to delete the record", vbYesNo)
   
   If rResult = vbYes Then
       conn.Execute "Delete * from Employee where EmployeeID =" & DataGrid1.Columns(0).Value
       
       Set DataGrid1.DataSource = Nothing
       Set rec = Nothing
       
       Set rec = New ADODB.Recordset
       rec.Open "Select * from Employee", conn, adUseClient, adLockOptimistic
       Set DataGrid1.DataSource = rec
   End If
End Sub

Private Sub DataGrid1_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
    Dim rResult
    rResult = MsgBox("Do you want to Edit the record", vbYesNo)
   
   If rResult = vbNo Then
       Cancel = True
       DataGrid1.ReBind
   End If
End Sub

Private Sub DataGrid1_BeforeDelete(Cancel As Integer)
   Dim rResult
   
   rResult = MsgBox("Do you want to delete the record", vbYesNo)
   
   If rResult = vbNo Then
       Cancel = True
   End If
End Sub

Private Sub DataGrid1_Error(ByVal DataError As Integer, Response As Integer)
   Response = False
End Sub

Private Sub Form_Load()
   conn.Open "test"
   rec.Open "Select * from Employee", conn, adUseClient, adLockOptimistic
   
   Set DataGrid1.DataSource = rec
   DataGrid1.AllowUpdate = True
End Sub

it doesn't work

What is not working? Debasisdas's code is correct. You should know by now to show us the error and on which line it occurs. That way we can help you get the solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.