DataGrid.GetChanges and DataSet.WriteXml

P

Paul

I am writing a DataBase Client/Server pair of applications in C#. The
client registers a query, the server populates a dataset and its
contents sent via XML to be displayed in the client DataGrid. This
works fine.
When the data is modified in the client DataGrid, the
DataGrid.GetChanges call populates the change dataset which is
transferred back to the server and the DataAdapter is Updated. This is
where I am having a couple of problems:
1. Any deletes are not captured in the change dataset XML.
2. There is no difference between modifications and additions in the
change dataset XML.

2. can be demonstrated in that if a record is edited in the client a
new record is inserted on the server side.

Your help is appreciated.
 
M

Mohamoss

Hi paul
to issue one:

this keep the state as deleted ( DataRowState.Deleted) you have to redelete
it
here is an example
for( int idx = 0; idx < r.Count; idx++ )
{
DataRow row = mytable.Rows[ idx ];
if( row.RowState == DataRowState.Deleted )
{
if( row[ mycolumn, DataRowVersion.Original ].ToString()== "12.2" )
{
r.RemoveAt( idx );
idx--;
}
}
else
{
if( row[ mycolumn].ToString() == "12.2" )
{
r.RemoveAt( idx );
idx--;
}
}
}

to issue two:
you have to define a primary key in each table in both sides ( clint and
server ) . this is the way by which the ado can differenciate between a new
row and an edited row .
for example :
if we have name id and age table with no primary key
how would ado know that mark 2
23 is the edited values of mark 2 25 and not
a new row!!!
however if we know that id 2 is the id then we can know that it is an
edited values of the same row.
to create a primary key we set the primary key properity to an array of
datacolumns
this is an example of table creation with a primary key
DataTable US = new DataTable("us");
DataColumn name = new DataColumn("name");
DataColumn ID = new DataColumn("ID");
DataColumn Ext = new DataColumn("Phone Ext");
US.Columns.Add(name);
US.Columns.Add(ID);
US.Columns.Add(Ext);
US.PrimaryKey =new DataColumn[]{ ID};

hope this would help
 

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