How to save edited grid data back to database

  • Thread starter Thread starter Sacha Korell
  • Start date Start date
S

Sacha Korell

How can I save data that was pulled into a grid and edited, back to the
database?

I read the article:
Using the DataGrid Control in Pocket PC Applications
http://msdn.microsoft.com/mobility/...rary/en-us/dnppc2k3/html/datagrid_control.asp

The article does explain how to edit the data in the grid, but apparently
not how to save it back to the database.
Am I missing something?

To edit the data in my application's grid, I actually used the sample
provided at gotdotnet.com
(http://samples.gotdotnet.com/quickstart/CompactFramework/doc/datagrideditin
g.aspx) which works quite well for editing the data, but what good is
editing if you can't save it back to the database ;-)

Thanks,

Sacha
 
In the first example, you could just use ds.WriteXML for instance to persist
the edited data back to XML.

As for getting stuff back into the DataBase....

Depending on your dataacess strategy, most likely you are using a
DataTable/DataSet. and have them filled with a DataAdapter...you will need
to use a DataAdapter's Update method to send the data back.
 
Ok, I had to declare the DataAdapter and the DataSet used to populate the
grid at the top as Private. Saving data seems to work now. Now I just have
to figure out how to clear the grid before every scan, because every time I
set the data source of the grid, it append the retrieved data to the
previously populated grid. Any idea? I wish there was a "datagrid.clear()"
method (or is there?).

Thanks,

Sacha
 
Sacha:

Are you looping through the table and adding rows or using the
DataGrid.DataSource? If the latter, then I think you might be calling Fill
on the same table multiple times b/c resetting the grids DataSource will
bind it to the DataTable.

Just for kicks...check the .Rows.Count property of the underlying table when
you notice that the rows are appended....If that's the case, you can use
DataTable.Clear before calling the second fill.
 
That's exactly what happened. I'm using the Datagrid.Datasource property to
fill the grid. All I had to do was call the DataSet.Clear() every time
before I populate it (i.e. scan a barcode) and it solved my problem.

Thanks,

Sacha
 
Back
Top