DataGrid Updates

  • Thread starter Thread starter Val
  • Start date Start date
V

Val

Hi,
My progy for a book shop shows stock, it has a tabcontrol with 3 tabs, on
each page thers a DataGrid (dg).
For each DataGrid thers a oleDbDataAdapter (da) and a DataSet (ds).
All 3 datasets pull data from the same table through their
DataAdapters - each with a different query; so da1 fills ds1 wiv all the
records (select * from books),
da2 fills ds2 wiv low stock (select * from books where stock<wotever) and
da3 fills ds3 wiv no stock (select * from books where stock = 0).

When user edits the records another form (dialog) pops up, upon completion
user clicks "Save Data" and the changes are put into ds1.
It then calls "da1.Update(ds1)" to save all the changes.

The problem:
When changes are saved from ds1 to the database I then try and update the
other DataSets by refilling them and redrawing the DataGrids like so:
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
private void updateStuff()

{

oleDbDataAdapter1.Fill(ds1,"Books");

oleDbDataAdapter2.Fill(ds2,"Books");

oleDbDataAdapter3.Fill(ds3,"Books");

dataGrid1.Update();

dataGrid2.Update();

dataGrid3.Update();

}

////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
BUT! Only DataGrid1 (dg1) updates correctly, the other 2 usually stay the
same, but sometimes do work.
I was braking my head for ages now and still cant figure out why. I tried
Refresh instead of Update to redraw DataGrids, but that didn't do anything
different.

Thanks everyone!
 
Thanks fanor,
But no, still does the same thing:
On "No Stock" tab, i change the Stock value to 2, press save changes and the
record is still there on the DataGrid (dg3) wiv 0 in Stock. But its dataset
(ds3) will have the correct value!
 
Fixed it, I had to clear the dataset before refilling it.
For some reason old data in the dataset does not get overwritten when the
dataset is refilled.........didnt find any documentation on this...stupid.

This is the new update function:
/////////////////////////////////////////////////////////////

private void updateStuff()

{

document1.Clear();

document2.Clear();

document3.Clear();

oleDbDataAdapter1.Fill(document1,"Books");

oleDbDataAdapter2.Fill(document2);

oleDbDataAdapter3.Fill(document3);

}

/////////////////////////////////////////////////////////////
 
Back
Top