locoboy locoboy - 1 year ago 98
SQL Question


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);

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

Right now i'm getting an error:

Incorrect syntax near '*'

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download