简体   繁体   English

如何更新DataTable

[英]How to Update DataTable

I have a main DataSet which contains several DataTables . 我有一个主DataSet包含几个DataTables These different DataTables are bound to their DataGridView's DataSource respectively. 这些不同的DataTable分别绑定到DataGridView的DataSource。

My problem is whenever I modify something in the display area such as the description textbox below and then click on save.... 我的问题是每当我修改显示区域中的某些内容时,如下面的描述文本框,然后单击保存....

描述 <<< To >>> <<< To >>> 修改说明

The DataGridView doesn't have the replicated changes, as seen here: DataGridView没有复制的更改,如下所示: DataGridView结果

I need a way to update the DataTable ... My save button successfully saves the information. 我需要一种方法来更新DataTable ...我的保存按钮成功保存了信息。 I am quite new to DataSets and DataTables so this is my first time trying to update a DataTable. 我是DataSets和DataTables的新手,所以这是我第一次尝试更新DataTable。 I doubt I need to reload the information in the DataTable, there must be something more efficient? 我怀疑我需要重新加载DataTable中的信息,必须有更高效的东西吗?

Updating a DataTable With Unknown Indexes 使用未知索引更新DataTable

For more information: How to: Edit Rows in a DataTable 有关更多信息: 如何:编辑DataTable中的行

In order to edit an existing row in a DataTable, you need to locate the DataRow you want to edit, and then assign the updated values to the desired columns. 要编辑DataTable中的现有行,您需要找到要编辑的DataRow,然后将更新的值分配给所需的列。


Update existing records in typed datasets (Row index not known) 更新类型化数据集中的现有记录(行索引未知)

Assign a specific DataRow to a variable using the generated FindBy method, and then use that variable to access the columns you want to edit and assign new values to them. 使用生成的FindBy方法将特定DataRow分配给变量,然后使用该变量访问要编辑的列并为其分配新值。

Dim Description As String = "Hello World Modified"

'Update DataTable
Dim Row As DataSet1.DataTableRow
Row = DataSet1.DataTableRow.FindByPrimaryKey(PK)
Row.Description = Description

Update existing records in untyped datasets (Row index not known) 更新无类型数据集中的现有记录(行索引未知)

Use the Select method of the DataTable to locate a specific row and assign new values to the desired columns 使用DataTable的Select方法查找特定行并将新值分配给所需的列

Dim Description As String = "Hello World Modified"

'Update DataTable
Dim Row() As Data.DataRow
Row = DataSet1.Tables("Table1").Select("PrimaryKey = '10'")
Row(0)("Description") = Description

Once this is done, I don't need to refresh anything else - my DataGridView has the latest information. 完成后,我不需要刷新任何其他内容 - 我的DataGridView具有最新信息。

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

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