How I can truncate a table with c#.
I do this but it doesn't work.
cmd.CommandText = "TRUNCATE TABLE dalbara;";
cmd.ExecuteNonQuery();
Visual Studio give me this error:
Invalid SQL command, you only can do 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT' or 'UPDATE'
I want to delete and restart all of my access table. With the DELETE command, the autoincrement values, doesn't reset.
MySqlConnection connection = new MySqlConnection(Server=localhost;Database=dbase;Uid=root;password=;)
string query = "TRUNCATE TABLE " + yourTableName
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.ExecuteNonQuery();
Use this code to truncate table
If you're some sort of database context you can do this:
dbContext.ExecuteCommand("TRUNCATE TABLE <tableName>");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With