That's the easiest way to delete all rows from the table in dbms via DataAdapter
. But if you want to do it in one batch, you can set the DataAdapter's UpdateBatchSize
to 0(unlimited).
Another way would be to use a simple SqlCommand
with CommandText DELETE FROM Table
:
using(var con = new SqlConnection(ConfigurationSettings.AppSettings["con"]))
using(var cmd = new SqlCommand())
{
cmd.CommandText = "DELETE FROM Table";
cmd.Connection = con;
con.Open();
int numberDeleted = cmd.ExecuteNonQuery(); // all rows deleted
}
But if you instead only want to remove the DataRows
from the DataTable
, you just have to call DataTable.Clear
. That would prevent any rows from being deleted in dbms.