You need to define connection for
sqlcommand[
^], like this:
SqlConnection conDelete = new SqlConnection(_connString);
conDelete.Open();
SqlCommand cmdDelete = new SqlCommand("DELETE FROM Students WHERE StudentId=1", conDelete);
int retVal = cmdDelete.ExecuteNonQuery();
Remember, you need to define records range to
DELETE (T-SQL)[
^], but if you want to delete all data, WHERE statement is not needed:
DELETE
FROM Students
Above query differs from
TRUNCATE TABLE (T-SQL)[
^].