简体   繁体   English

使用LINQ和tableadapter时如何从数据库中删除所有记录?

[英]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. 我正在尝试将数据从Excel文件加载到Form中的DataGridView。 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. 首先,我将所有数据从excel工作表加载到数据集中,然后使用C#LINQ将所有数据放入数据库中,然后将DataGridView.DataSource设置为name.BindingSource,就是这样。 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 just appendend to the previous data but I want only the new data... 我在DataGridView中获取了所有数据,但是当我尝试再次加载数据时(我已关闭程序并更改了Excel中的某些单元格),新数据只是追加到先前的数据中,但我只希望新数据...

So my question is: How to delete all records in database or in LINQ or TableAdapter just to delete RECORDS.... :) getting frustrated by this. 所以我的问题是:如何删除数据库或LINQ或TableAdapter中的所有记录只是为了删除RECORDS .... :)对此感到沮丧。

I am trying to clear a database dataset by using nameDBDataset.table.Clear() but nothing, trying to use TableAdapter to delete but again nothing. 我试图通过使用nameDBDataset.table.Clear()来清除数据库数据集,但是什么也没有,试图使用TableAdapter删除但又什么也没有。

help please... 请帮助...

Thank you all! 谢谢你们!

I found the answer, its really quite simple... duh :) 我找到了答案,这真的很简单... duh :)

nameDataContext dc = new nameDataContext(); dc =新的nameDataContext();
dc.ExecuteCommand("TRUNCATE TABLE name-of-the-table"); dc.ExecuteCommand(“ TRUNCATE TABLE表的名称”);

Thats it... 而已...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM