如何将DataGridView中发生的变化保存到Table C#中?

问题描述 投票:0回答:1

我知道,过去也有人提出过类似的问题。 但是,我真的很难理解这个概念。 我已经有20年没有从事Windows Form Application的构建工作了,我被交给别人的老项目来支持。

我有一个DataGridView,它是由一个DataSource填充的。 BadgerHistoryBindingSource。

我认为这是DataGrid填充的地方. .

// TODO: This line of code loads data into the 'badgerDataSet3.Badger_History' table. You can move, or remove it, as needed.
this.badger_HistoryTableAdapter.Fill(this.badgerDataSet3.Badger_History);

DataGird已经启用了 "EDIT"。 然而,我很难理解当点击保存按钮时,如何将这些更改从DataGrid保存到SQL表中。

从我读到的内容来看......这些更改是自动从DataGrid保存到数据表(badgerDataset3.Badger_History)的? 我必须把它们从DataTble保存到SQL表? 我在这里的路径是正确的吗? 谁能给我一个例子让我看看,这样我就可以解决这个问题了?

更新. 只是为了表明我正在尝试(但失败了)......这是我的位置。 我甚至不确定我是否走在正确的道路上......。.

 ds = badgerDataSet3;
 DataSet changes = this.ds.GetChanges();
 if (changes != null)
 {
 //Data has changes. 
 //use update method in the adapter. it should update your datasource
 int updatedRows = this.dataAdapter.Update(changes);

 this.ds.AcceptChanges();
 MessageBox.Show("Change Saved");
 }

我知道这是不工作的,因为它是嵌入在一个尝试。.当我运行它时,我从来没有得到 "更改保存 "消息框。

c# datagridview datatable datasource
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.