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.DataSou rce;
DataRow rowToDelete = ds.Tables["Msgs"].Rows[row Idx];
rowToDelete.Delete();
DataSet changes = ds.GetChanges();
if (changes != null)
{
string changesString = changes.GetXml();
MessageBox.Show(changesStr ing);
}
My code to delete and get changes is below.
int rowIdx = dataGrid1.CurrentRowIndex;
DataSet ds = (DataSet)dataGrid1.DataSou
DataRow rowToDelete = ds.Tables["Msgs"].Rows[row
rowToDelete.Delete();
DataSet changes = ds.GetChanges();
if (changes != null)
{
string changesString = changes.GetXml();
MessageBox.Show(changesStr
}
You can use ds.GetChanges(DataRowState .Deleted) to get only the deleted rows.
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?
DataSet changes = ds.GetChanges(DataRowState
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
RejectChanges works great! The DiffGram would also work, but it's more work than is needed. I'll split up the points. Thanks