Click to See Complete Forum and Search --> : Updating datagridview from table?


glynn1280
April 10th, 2008, 03:28 PM
When I delete a record from the datagridview it also updates the database. When I reload the form everything stays deleted. I used the following code...

Code Snippetprivate void borrowersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
customerTableAdapter.Update(cm05501DataSet.Customer);
}

However, when I add a new record, save, exit and reload the form the new record is not there. The newly added record is infact saved to the acutal database, but for reasons unknown is not saved to the datagridview and does not show when the form is loaded. I used the following code in form_load and save...

Code Snippetprivate void Form1_Load(object sender, EventArgs e)
{

this.Validate();
this.customerBindingSource.EndEdit();
this.customerTableAdapter.Fill(this.cm05501DataSet.Customer);
}
Code Snippetprivate void borrowersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{

customerTableAdapter.Update(cm05501DataSet.Customer);

}

nelo
April 10th, 2008, 05:52 PM
Hi there,

Try and use code tags next time. It makes your code more readable. Now for your problem. I assume that you've set cm05501DataSet.Customer as the data source for customerBindingSource. Is that correct? In that case try this:

private void borrowersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
customerTableAdapter.Update(cm05501DataSet.Customer);
customerBindingSource.ResetBindings(false);
}

glynn1280
April 10th, 2008, 06:58 PM
Sorry! And that is correct, but the above code still did not work.

When you edit or delete existing data, the form actually does save it. But, when I add a new row to the end (bottom) row of the datagridview it only saves that to the access database and not to the datagridview, hence it dissapearing on reloading the form.

I've checked that insert, delete, etc are configured on the datasource and I've tried the endedit method, but nothing seems to be working.