PC Review


Reply
Thread Tools Rate Thread

Dataset issue with Constraints

 
 
bjako
Guest
Posts: n/a
 
      19th Feb 2005
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.
 
Reply With Quote
 
 
 
 
W.G. Ryan eMVP
Guest
Posts: n/a
 
      21st Feb 2005
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.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"bjako" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
bjako
Guest
Posts: n/a
 
      22nd Feb 2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dataset Constraints - again Woody Splawn Microsoft ADO .NET 2 4th Aug 2005 03:00 PM
Dataset constraints Woody Splawn Microsoft ADO .NET 2 29th Jul 2005 04:16 PM
DataSet constraints Glenn Thimmes Microsoft ADO .NET 1 31st May 2005 11:30 AM
DataSet constraints Bert Sachs Microsoft ADO .NET 1 11th May 2004 12:13 PM
Database constraints and dataset constraints Rapi Microsoft ADO .NET 1 24th Dec 2003 12:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:59 AM.