简体   繁体   English

在 Winforms 中向 DataGridView 添加编辑工具

[英]Adding Edit Facility to DataGridView in Winforms

I've populated a DataGridView using a DataSet.我已经使用 DataSet 填充了 DataGridView。 Now I've to add edit functionality to this DataGrid.现在我要向这个 DataGrid 添加编辑功能。 But changing data in SQL server in every value changed event will be of much overhead.但是在每个值更改事件中更改 SQL 服务器中的数据会产生很大的开销。 So after changing the cells in intended rows, the user will press a submit button and the data only in the changed cells will be submitted to the SQL server.因此,在更改预期行中的单元格后,用户将按下提交按钮,并且仅更改的单元格中的数据将提交到 SQL 服务器。

Can you give a full example on this.你能给出一个完整的例子吗? Or some kind of good link on this.或者某种好的链接。 I've searched a lot.我已经搜索了很多。 But couldn't find anything helpful.但是找不到任何有用的东西。

Again using dataset quite a bit old fashioned.再次使用相当过时的数据集。 Can you give me an example to do this in LINQ.你能给我一个例子在 LINQ 中做到这一点。

Thanks a lot in advance.提前非常感谢。

If I were you, I would cache the changes.如果我是你,我会缓存更改。 Then at regular intervals, or when you cached so many changes, on when the form that holds the grid closes (On/Closing event), I would commit the changes.然后每隔一段时间,或者当你缓存了这么多更改时,当保存网格的表单关闭时(On/Closing 事件),我会提交更改。 Or how about you let the users update as many cells they want.或者您如何让用户更新他们想要的多个单元格。 Then you have a single submit button somewhere on that form, and when the user presses it, you commit to the database and close the form or whatever.然后,您在该表单的某处有一个提交按钮,当用户按下它时,您提交到数据库并关闭表单或其他任何东西。

Regarding linq, is fairly similar to create a linq query that emulates any SQL statement used to populate the DataSet.关于 linq,与创建 linq 查询非常相似,该查询模拟用于填充数据集的任何 SQL 语句。 Or consider using LINQ-to-SQL or Entity Framework, depending on your project.或者考虑使用 LINQ-to-SQL 或实体框架,具体取决于您的项目。

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

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