By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

Inserting new rows into child when parent ID is autoincrement

P: n/a
I have a parent table that has one child table. The parent has a single
field (ID, AutoIncrement, Seed 0, Step -1 in the DataSet, Seed 1, step
1, in DataSource). The child is linked to this ID column in the parent.
I have the parent fields in textboxes and the child is a DataGrid. When
I add a new parent record, then go to add child records, I am getting an
exception that says, "ForeignKeyConstraint requires the child key values
(0) to exist in the parent table. Do you want to correct the value?" ..
I've tried multiple things to fix this, and it doesn't seem to work
right. The first thing I did was make sure I did a EndCurrentEdit when
entering the grid. Well, that helped.. However, the ID of the parent and
Child were both 0, and when it saved it to the datasource, the ID of the
parent changed and all the child records were lost. So, I then added
code to the entering event to endcurrentedit and then Update so that the
real ID would show up. Then I started to get that child key values error
again. So in the Entering event I added the code to set the default
value of the ID column in the child to the new parent ID. I still get
the same error. If I save the parent, navigate off that record and then
back to it, I can enter in child records all day, it works fine, even
without all the entering even code.. It's just on new records. What else
do I have to do here?

Thanks
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

i have the same problem. how can i get the parent ID value to b
inserted into child rows??

--
kimic
-----------------------------------------------------------------------
kimico's Profile: http://www.msusenet.com/member.php?userid=2
View this thread: http://www.msusenet.com/t-30549

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.