2
Answers

How to delete current row in DataGridView?

mohamad guntur

mohamad guntur

12y
1.7k
1
i have an error when using this function,,i want to delete the data at the current rows. Of course when i'm deleting the rows, the selected data on the database must be deleted.

here is my code

 Try
            If Not con.State = ConnectionState.Open Then
                con.Open()
            End If

            Dim cmd As New SqlCommand
            cmd.Connection = con
            cmd.CommandText = "DELETE FROM PRODUCT WHERE ID_PRODUCT=" & Me.DataGridView1.CurrentRow.Cells(0).Value & "'"
            cmd.ExecuteNonQuery()
        Finally
            con.Close()
        End Try


thanks in advance


Answers (2)