简体   繁体   中英

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 . Set it to false or call Fill() on the Clients table before adding the new row.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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