467,136 Members | 1,366 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,136 developers. It's quick & easy.

Dataset and identity seed columns

I have a dataset that contains two tables - Parent and Child. The key of the
Parent is called ParentID and is an identity column in SQL Server. The key of
the Child is two columns called ParentID - foreign key defined as INT to
Parent table - and ChildID that in itself is an identity column. I have used
the designer to create a relationship within the dataset for the two tables.

I have set the dataset so the ParentID column starts at -1 and increments
which works fine as in code I can make sure that the FK on the Child table is
updated correctly.

The problem is when I try to update the datasource with the dataset. What
happens is the ParentID column on the Parent table is changed by the
database, say from -1 to 101 (which is the next seeded value for that table)
but this change is not cascaded down to the Child table and this trys to add
its records where the FK column still has the value -1, hence SQL Server then
kicks off with constraint errors.

If I use the dataset Edit Relation form so the update rule etc. is changed
from Default to Cascade then the error doesn't happen as the data from the
Child table is not inserted into the database (and no errors in .Net to tell
me it didn't do the insert!)

What am I doing wrong as I can't believe it won't be allowed ?

Jul 21 '05 #1
  • viewed: 1544
Share:
1 Reply
Stephen,

If I was you, I would ask this question in the newsgroup

Adonet
news://msnews.microsoft.com/microsof...amework.adonet

Web interface:
http://communities2.microsoft.com/co...amework.adonet

There William(Bill)Vaughn loves to answer this kind of questions. (Or better
he does not, however he investigate this problem very well)

You can as well look at this page from him
http://msdn.microsoft.com/library/de...anidcrisis.asp

I hope this helps,

Cor
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by William Ortenberg | last post: by
8 posts views Thread by Bruce Stockwell | last post: by
10 posts views Thread by Eric Petruzzelli | last post: by
1 post views Thread by Stephen Ritchie | last post: by
1 post views Thread by matt@mailinator.com | last post: by
11 posts views Thread by stegze | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.