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(newCl开发者_开发问答ientRow);
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?
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.
Check if clientsAdapter.ClearBeforeFill
is set to true
. Set it to false
or call Fill()
on the Clients
table before adding the new row.
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.
精彩评论