Dataset issue with Constraints

B

bjako

Hi, I'm going out of my mind with this one.

I have a dataset with a number of tables with parent/child relations
enforced.

I'm trying to replace a row in a parent table, but the issue is that
it sets the rowstate of all the child records in the related tables to
'Deleted'.

This is understandable given the constraint. However the row I am
replacing in the parent table has the same key so once completed the
child rows don't need to be deleted.

The question is how do I do that? I've tried turning off enforce
constraints but that didnt seem to work. Even setting Relations.clear
still deletes the child records on deleting the parent!

My code currently looks like this:

ContractDS.EnforceConstraints = False
Dim drs As DataRow() = ContractDS.Tables(TableName).Select(KeyName &
"='" & KeyValue & "'")
ContractDS.Tables(TableName).Rows.Remove(drs(0))
ContractDS.Tables(TableName).NewRow()
ContractDS.Tables(TableName).ImportRow(dr)
ContractDS.EnforceConstraints = True

I've been going round in circles for hours. The only way I can make it
work is to create the dataset without ANY relations in the first place
which is not ideal.

Any help is most appreciated.

Thanks, Ben.
 
W

W.G. Ryan eMVP

BJako:

I'm not sure I'm following the goal hwere. You're calling Remove (which
takes that row(s) out of the collection vs delete.

From this snippet - it's hard to tell what's going on. I think simply using
Delete instead of remove will work for you if you're adding the parent.

One easy way is to build a relation on another field - but I'd need to know
a little more about the end goal to make that recommendation.
 
B

bjako

Hi William,

Thanks for your time.

As with most complex problems when you hit a roadblock it forces you
to re-evaluate the way you are doing something.

Then it hit me like 'a ton of bricks' on Sunday... that I was trying
to bolt new functionality onto an existing way of doing something
without first analysing whether the whole approach should change.

The solution is I have re-architected the approach which has
effectively eliminated the problem by doing it better in the first
place :)

Thanks for your help. Without going into a long winded explanation it
all works now.

Regards, Ben.
 

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