Hi,

This is a strange problem...

I have a Access database with 2 tables, a master with 1 primary key (pk) and a child with 2 pk's.
One client can have one or more orders.

Clients
*id
name

Orders
*fkClient
*id
units
price

So far so good.
I created in VS2003 using the "DataForm Wizard" a simple master-detail form with the "Single record with individual controls" option. (I only have this problem with this option, there's no problem with to data grids).
This creates a simple data form with some text boxes and a data grid, witch is ok view data..

The problem is, when i add a new record (this only happends to the new added records) and when a insert a new row on the data grid I get the folowing error

"Error when commiting the row to the original data store :
ForeignKeyConstraint rel_FKClient_ID requires a child key value (1) to exist in the parent table. Do you want to correct the value?"


The dataset is MyDS and the relation is parent.id to client.fkClient.
I beliave that this is due to the fact that the new created record does not yet exist in the parent dataset.
But why!? Instead of having individual controls if I put 2 datagrid, one for the parent and the one for the child, this problem does not exist.
I have tried to put an autoincrement, just for testing, and when i add a new row to the orders datagrid the correct client id appears, but the problem remains.
How can I overcome this without having to update the dataset before adding a new row to the child datagrid.

Please share some information, cause I'm freaking out.......
Thanks to all.

--------------------------------
From: Rui Gon?alves

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>rxyhmE7dn06wiA5MoAlEiw==</Id>

Re: Datagrid Child Insert New Row ForeignKeyConstraint Problem by Miha

Miha
Thu May 13 14:22:32 CDT 2004

Hi,

Am I correct asuming that you are trying to insert a record into child table
while the parent record is not there?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Rui Gon?alves via .NET 247" <anonymous@dotnet247.com> wrote in message
news:ONpq7dQOEHA.1160@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> This is a strange problem...
>
> I have a Access database with 2 tables, a master with 1 primary key (pk)
and a child with 2 pk's.
> One client can have one or more orders.
>
> Clients
> *id
> name
>
> Orders
> *fkClient
> *id
> units
> price
>
> So far so good.
> I created in VS2003 using the "DataForm Wizard" a simple master-detail
form with the "Single record with individual controls" option. (I only have
this problem with this option, there's no problem with to data grids).
> This creates a simple data form with some text boxes and a data grid,
witch is ok view data..
>
> The problem is, when i add a new record (this only happends to the new
added records) and when a insert a new row on the data grid I get the
folowing error
>
> "Error when commiting the row to the original data store :
> ForeignKeyConstraint rel_FKClient_ID requires a child key value (1) to
exist in the parent table. Do you want to correct the value?"
>
>
> The dataset is MyDS and the relation is parent.id to client.fkClient.
> I beliave that this is due to the fact that the new created record does
not yet exist in the parent dataset.
> But why!? Instead of having individual controls if I put 2 datagrid, one
for the parent and the one for the child, this problem does not exist.
> I have tried to put an autoincrement, just for testing, and when i add a
new row to the orders datagrid the correct client id appears, but the
problem remains.
> How can I overcome this without having to update the dataset before adding
a new row to the child datagrid.
>
> Please share some information, cause I'm freaking out.......
> Thanks to all.
>
> --------------------------------
> From: Rui Gon?alves
>
> -----------------------
> Posted by a user from .NET 247 (http://www.dotnet247.com/)
>
> <Id>rxyhmE7dn06wiA5MoAlEiw==</Id>