locoboy locoboy - 3 months ago 9
SQL Question

DELETE*FROM table

Is there a way (similar to the below code) to delete all the rows in a specified table using c#?

SqlConnection con = new SqlConnection(conString);
con.Open();

string sql = @"DELETE*FROM compsTickers;";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();


Right now i'm getting an error:


Incorrect syntax near '*'

Answer

There's nothing wrong with your C# code; that's an SQL syntax error.

Anyway, there's no need for the *. You delete rows, not columns, from a table, so you don't specify columns to delete:

DELETE FROM compsTickers