keynesiancross
keynesiancross

Reputation: 3529

mySQL .NET API - Delete all data from table

I'm trying to figure out if there is an easy way to delete all the data in a table using the MySQL .NET API. The only slightly more tricky part to this is that in the C# code, the business logic can be run in both cases where there is, or isn't, data in the table. So in some regards I almost need an If statement...

Currently I am using the following code, but it doesn't seem to ever delete data...

string deleteSQL = "DELETE FROM `data`.`currentData`";
MySqlCommand cmd2 = new MySqlCommand(deleteSQL, conn);

Any thoughts would be much appreciated!

Upvotes: 1

Views: 2800

Answers (3)

Trevor Tiernan
Trevor Tiernan

Reputation: 522

Maybe this is a dumb idea. But what about just dropping the table and recreating it?

Upvotes: 0

The Scrum Meister
The Scrum Meister

Reputation: 30131

The sql looks good, make sure you call cmd2.ExecuteNonQuery(); and the connection is properly setup, and the user has DELETE permission.

Upvotes: 3

AndyM84
AndyM84

Reputation: 139

You should use the TRUNCATE command instead. That will also reset any auto_increments you have.

http://dev.mysql.com/doc/refman/5.0/en/truncate-table.html

Upvotes: 3

Related Questions