How to erase all records from a database when using LINQ and tableadapter?
I am trying to load data from Excel file to DataGridView in my Form. First I load all data from excel sheet into dataset then put all that data in database using C# LINQ and then I just set the DataGridView.DataSource to name.BindingSource and that is it. I get all the data in DataGridView but when I try to load the data again (I have closed my program and changed some cells in Excel) the new data is j开发者_开发问答ust appendend to the previous data but I want only the new data...
So my question is: How to delete all records in database or in LINQ or TableAdapter just to delete RECORDS.... :) getting frustrated by this.
I am trying to clear a database dataset by using nameDBDataset.table.Clear() but nothing, trying to use TableAdapter to delete but again nothing.
help please...
Thank you all!
I found the answer, its really quite simple... duh :)
nameDataContext dc = new nameDataContext();
dc.ExecuteCommand("TRUNCATE TABLE name-of-the-table");
Thats it...
精彩评论