The delete operation is used to delete records from a table. A filter must be specified for the operation to take place (or you may end up deleting everything!)
DELETE FROM Customers WHERE State = @State
Deletes all the customer records matching the parameter of State..
Note the following code sample:
Public Sub deleteFromCart(CartID As Integer)
Dim myConn As SqlConnection = New SqlConnection(MyConnString)
myConn.Open()
Dim strSQL As String = "DELETE FROM XYZCart WHERE CartID = @CartID"
Dim myComm As SqlCommand = New SqlCommand(strSQL, myConn)
myComm.Parameters.AddWithValue("@CartID", CartID)
myComm.ExecuteNonQuery()
myConn.Close()
End Sub
Once again, parameters are used to pass the criteria used to delete the records and the ExecuteNonQuery method of the command object is engaged to complete the operation.