Dataset problem

P

Park2

Visual studio 2005 C#.

I have the following code

DataTable table;

table = dataSet1.Tables["Park1"];

// Use the NewRow method to create a DataRow with

// the table's schema.

DataRow newRow = table.NewRow();

// Set values in the columns:

newRow["Column1"] = "NewCompanyID";

newRow["Column2"] = "NewCompanyName";

// Add the row to the rows collection.

table.Rows.Add(newRow);

// Save Changes

dataSet1.park1.DataSet.AcceptChanges();

I created the datasource in visual studio by

adding new item

adding dataset

created a table called Park1 with colums.

Inc (Key)

column1

column2

When I run on my device all goes as planned except I cannot edit the data in
the grid and when I exit the app and re-run the table does not retain the
data.



Any help appreciated
 
I

Ilya Tumanov [MS]

NETCF's DataGrid is read-only, so you can not change anything in it. Also,
you should not expect your data to be persisted as you have no code to
actually do it. DataSet.AcceptChanges() does not save your data, it just
marks all rows as Unchanged in memory.



To persist your data you should call DataAdaper.Update() if you're
connecting to some data base (e.g. SQL Mobile or SQL Server 2000/2005) or
you could save your data to XML using DataSet.WriteXml() and load it back
with DataSet.ReadXml().



Do not call AcceptChanges() if you're using DataAdaper as it only updates
changed rows as you won't have any after AcceptChanges() called.
DataAdapter.Update() would call AcceptChanges() automatically after data has
been stored in data base.


--
Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top