问题描述
你好!
我在winform上有一个datagridview,其中从ms Access数据库填充表的记录.我希望datagridview是可编辑的,所以我启用了datagridview的编辑.但是对gridview单元格或行所做的更改未保存在数据库中,因此当我再次运行该应用程序时,它不会在datagridview中显示已编辑的记录.
如何使datagrid视图可编辑,并且在编辑记录后必须将其保存在数据库中.
感谢
Hello!!
I have a datagridview on my winform in which i m populating the records of a table from ms access database. I want the datagridview to be editable , so i enabled editing of datagridview. But the changes made to gridview cell or row are not saved in database, hence when i run the application again it doesn''t shows the edited records in datagridview.
How can i make datagrid view to be editable and after editing records must be saved in database.
Thanks
推荐答案
OleDbCommandBuilder build = new OleDbCommandBuilder(adapter);
用于构建upadate查询并在保存记录按钮上单击事件,请写以下行:
for building the upadate query and on save record button click event write the below line:
adapter.Update(dt);
其中adapter是OleDbDataAdapter的对象,而dt是DataTable的对象
谢谢.
where adapter is a object of OleDbDataAdapter and dt is object of DataTable
Thanks.
这篇关于编辑datagridview并将其保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!