Link to home
Start Free TrialLog in
Avatar of mromeo
mromeo

asked on

How do you get the Deleted DataRows of a DataSet?

My program uses DataRow.Delete to delete rows from a DataSet.  After they have been deleted, I check it's RowState which is Deleted and then I call GetChanges() on the DataSet.  The changes returned do not include the deleted rows.  If I can't use GetChanges after a series of Delete()'s to find out what has changed in the DataSet, what can I use to find out wihch rows  have been deleted.  Do I need to keep track of the deletions myself?

My code to delete and get changes is below.


int rowIdx = dataGrid1.CurrentRowIndex;
DataSet ds = (DataSet)dataGrid1.DataSource;
DataRow rowToDelete = ds.Tables["Msgs"].Rows[rowIdx];
rowToDelete.Delete();

DataSet changes = ds.GetChanges();
if (changes != null)
{
     string changesString = changes.GetXml();
     MessageBox.Show(changesString);
}

Avatar of Jesse Houwing
Jesse Houwing
Flag of Netherlands image

You can use ds.GetChanges(DataRowState.Deleted) to get only the deleted rows.
Avatar of mromeo
mromeo

ASKER

What am I supposed to get.  When I do

      DataSet changes = ds.GetChanges(DataRowState.Deleted);
      string c = changes.GetXml();

The string returned is just:

<MessageList xmlns=\"http://tempuri.org/Messages.xsd\" />

How can I get changes from that?


That's strange, are you sure you've deleted the rows? And not accidently called AcceptChanges or RejectChanges on the dataset?
Avatar of mromeo

ASKER



What should GetXml return?  Should it have the entire row in the xml string?
It should contain the whole dataset, including table and column definitions and all data. It looks like the dataset in question is completely empty.
ASKER CERTIFIED SOLUTION
Avatar of sumix
sumix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mromeo

ASKER

RejectChanges works great!  The DiffGram would also work, but it's more work than is needed.  I'll split up the points.  Thanks