在数据表中添加了行未显示?

时间:2022-12-14 18:54:06

I've a simple code, here I add a row to my a datatable which is in my dataset:

我有一个简单的代码,在这里我向我的数据集中的数据表添加一行:

 DigiLocalDataSet dataset = new DigiLocalDataSet();

 DataRow newClientsRow = dataset.Tables["clients"].NewRow();

 newClientsRow ["clientnr"] = "123";
 newClientsRow ["name"] = "Pascal";
 newClientsRow ["city"] = "London";

 dataset.Tables["clients"].Rows.Add(newClientRow);

 clientsTableAdapter.Fill(dataset.clients);

 this.DataContext = dataset.clients.DefaultView;

But I don't see the inserted row in my datagrid, I see only the existing rows of the 'clients' table.

但我没有在我的数据网格中看到插入的行,我只看到'clients'表的现有行。

What's wrong?

5 个解决方案

#1


1  

Your call to TableAdapter.Fill is filling your 'clients' DataTable with data retrieved from your data source, so you're losing the record you manually added to the DataTable.

您对TableAdapter.Fill的调用是使用从数据源检索到的数据填充“客户端”DataTable,因此您将丢失手动添加到DataTable的记录。

#2


1  

Check if clientsAdapter.ClearBeforeFill is set to true. Set it to false or call Fill() on the Clients table before adding the new row.

检查clientsAdapter.ClearBeforeFill是否设置为true。将其设置为false或在添加新行之前调用Clients表上的Fill()。

#3


1  

Have you tried this?

你试过这个吗?

 newClientsRow.BeginEdit();
 newClientsRow ["clientnr"] = "123";
 newClientsRow ["name"] = "Pascal";
 newClientsRow ["city"] = "London";
 newClientsRow.EndEdit();

#4


0  

I don't know the command but you need to post this row.

我不知道命令,但你需要发布这一行。

#5


0  

Did you accept changes to the dataset before refilling? fill pulls data from the store.

在重新填充之前,您是否接受对数据集的更改? fill从商店中提取数据。

#1


1  

Your call to TableAdapter.Fill is filling your 'clients' DataTable with data retrieved from your data source, so you're losing the record you manually added to the DataTable.

您对TableAdapter.Fill的调用是使用从数据源检索到的数据填充“客户端”DataTable,因此您将丢失手动添加到DataTable的记录。

#2


1  

Check if clientsAdapter.ClearBeforeFill is set to true. Set it to false or call Fill() on the Clients table before adding the new row.

检查clientsAdapter.ClearBeforeFill是否设置为true。将其设置为false或在添加新行之前调用Clients表上的Fill()。

#3


1  

Have you tried this?

你试过这个吗?

 newClientsRow.BeginEdit();
 newClientsRow ["clientnr"] = "123";
 newClientsRow ["name"] = "Pascal";
 newClientsRow ["city"] = "London";
 newClientsRow.EndEdit();

#4


0  

I don't know the command but you need to post this row.

我不知道命令,但你需要发布这一行。

#5


0  

Did you accept changes to the dataset before refilling? fill pulls data from the store.

在重新填充之前,您是否接受对数据集的更改? fill从商店中提取数据。