Strange HasChanges behaviour

P

Paul

Hi All,

I'm experiencing some strange behaviour of the DataSet.HasChanges()
method, the situation is as follows:-

1) Populate a DataSet with 2 tables Master and Details.
2) Setup a DataRelation between the 2 tables.
3) Configure the relation to have cascade Deletes on the
ChildKeyConstriant.
4) Delete a record from the Master table and the child records are also
removed. At this point everything works as expected, checking the row count
of both tables and the record have been removed.

Now checking the HasChanges() method returns false?

Any ideas as to what could be causing this?

TIA
Paul
 
P

Paul

No, I'm checking the HasChanges() method immediately after removing the row?
I'm totally lost with thos one, code below?

DataTable dtMaster = ds.Tables[0];
DataTable dtChild = ds.Tables[1];

int src = dtChild.Rows.Count;
DataRow[] rows = dtMaster.Select("UnitSpecNo = '" + unitSpec + "'");
foreach (DataRow row in rows)
dtMaster.Rows.Remove(row);
int erc = dtChild.Rows.Count;

//src = 254
//erc = 248

if (ds.HasChanges())
{
// Never called???
...
}
 
D

David Sceppa

HasChanges returns True if the DataSet contains pending
changes to submit to the database. Calling DataTable.Rows.Remove
removes the row from the collection. Once that's done, the
DataTable has no record of the row that was removed. If you're
looking to submit a pending deletion to the database, you should
call DataRow.Delete instead.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 

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