简体   繁体   English

未显示数据表中的添加行?

[英]Added Row in Datatable not shown?

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.但我没有在我的数据网格中看到插入的行,我只看到“客户”表的现有行。

What's wrong?怎么了?

Check if clientsAdapter.ClearBeforeFill is set to true .检查clientsAdapter.ClearBeforeFill是否设置为true Set it to false or call Fill() on the Clients table before adding the new row.在添加新行之前,将其设置为false或在Clients表上调用Fill()

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 的调用正在使用从数据源检索到的数据填充您的“客户”数据表,因此您将丢失手动添加到数据表中的记录。

Have you tried this?你试过这个吗?

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

I don't know the command but you need to post this row.我不知道命令,但你需要发布这一行。

Did you accept changes to the dataset before refilling?在重新填充之前,您是否接受了对数据集的更改? fill pulls data from the store. fill 从存储中拉取数据。

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

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