Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: no primary key value for foreign key value error in Master-Detail Dataset


This question is answered.


Permlink Replies: 1 - Last Post: Sep 14, 2014 9:05 PM Last Post By: Dmitry Arefiev
Jitendra Gouda

Posts: 11
Registered: 3/2/13
no primary key value for foreign key value error in Master-Detail Dataset  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 11, 2014 8:54 PM
Hi,

We are using master detail relationship dataset but getting primary key violation error during posting the data.


Project GBlWare.exe raised exception class EASANativeException with message
[FireDAC][Phys][ODBC][Sybase][SQLAnywhere]no primary key value for foreign key


Our current master detail scenario is that ,we are using parameter in details dataset that reference to master dataset primary key field value. But when I add a new record at that time master dataset key value is null. So when I press tab or down arrow in detail dataset grid it automatically posts detail data in database. As at that time master dataset is not posted to database, so it causes the foreign key violence exception.

In ADO we use Batchoptimistic property for detail dataset. So that user can add multiple detail data in details dataset. Then user can save batch of data to database at a time. On that period we first post master data and then we set detail foreign key value with master primary key value. So same thing I want to do in FIreDAC

Currently I am doing following setting
1. I have put a master query on form with sql
Select * from Order

2. On Detail query on form with SQL
Select * from OrderDetail where OrderID = :OrderID

3. I set Query detail master source as Tdatasource linked to Master query.

4. Then In detail query I set masterfild as Master dataset primary key. and indexfield name as detail query foreign key.

So am I missing any step ? Please suggest.

How can I implement same master-detail dataset functionality in FireDAC such that user can add multiple detail record at a time to database.?
So please suggest the proper way to implement it.

It would be better if any body please provide one demo.

Thanks,

Dmitry Arefiev

Posts: 1,406
Registered: 12/7/03
Re: no primary key value for foreign key value error in Master-Detail Dataset
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 14, 2014 9:05 PM   in response to: Jitendra Gouda in response to: Jitendra Gouda
http://docwiki.embarcadero.com/RADStudio/XE7/en/Caching_Updates_(FireDAC)
http://docwiki.embarcadero.com/RADStudio/XE7/en/Caching_Updates_(FireDAC)#Centralized_Cached_Updates

--
With best regards,
Dmitry Arefiev / FireDAC Architect
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02