[英]How to save cell changes from a datagrid to a SQL Server database?
I have loaded data from an Excel sheet via SqlBulkCopy
into a SQL Server 2016 database. 我已通过SqlBulkCopy
将数据从Excel工作表加载到SQL Server 2016数据库中。 Then I have loaded this table into a datagrid in C# & WPF. 然后,我已将此表加载到C#和WPF中的数据网格中。
Some cells are empty, and if I write something in them, I want to immediately (right after I pressed Enter or click on another cell) update my database. 有些单元格是空的,如果我在其中写入了一些内容,我想立即(在按Enter或单击另一个单元格之后)立即更新数据库。
I've looked up many solutions on the internet but none of them helped me. 我在互联网上查找了许多解决方案,但没有一个对我有帮助。
Thank you in advance and have a nice day! 在此先感谢您,祝您愉快!
You can use your datagrid's events: 您可以使用datagrid的事件:
Leave
: Occurs when the DataGridView loses focus; Leave
:在DataGridView失去焦点时发生;
CellLeave
: Occurs when a cell loses focus, ie it's no longer the current cell; CellLeave
:在单元格失去焦点时发生,即不再是当前单元格;
RowLeave
: Occurs when a row loses focus and is no longer the current row; RowLeave
:在某行失去焦点并且不再是当前行时发生;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.