mohamad guntur

mohamad guntur

  • NA
  • 40
  • 40.7k

How to delete current row in DataGridView?

Oct 2 2012 2:54 AM
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)