Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 22nd, 2013, 10:50 AM
bennywilks bennywilks is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 bennywilks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 22 sec
Reputation Power: 0
Inserting Data into Databases

Hi, Im having trouble adding my data into databases. I'm using the following code:

adotList.Append;
adotList['FixtureID'] := FixId;
adotList['OpponentID'] := OppId;
adotList['CompID'] := CompId;
adotList['FixtureDate'] := FixDate;
adotList['Venue'] := Ven;
adotList.Post;
if Ven = 'A'
then
begin
adotOpponent.Append;
adotOpponent['OpponentID'] := OppId;
adotOpponent['Opponent'] := ledtOpponent.Text;
adotOpponent['Address'] := ledtAddress.Text;
adotOpponent.Post;
end
else
begin
adotOpponent.Append;
adotOpponent['OpponentID'] := OppId;
adotOpponent['Opponent'] := ledtOpponent.Text;
adotOpponent.Post;
end;
adotComp.Append;
adotComp['CompID'] := CompId;
adotComp['Competition'] := ledtCompetition.Text;
adotComp.Post;
end;

When I press the Add Button only the data for the List table is being entered, The error Message is ' You cannot change or add a record because a related record is required in table 'Competition'. Also When I close the application the data that does get entered is being saved into my database.

Any Help would be greatly appreciated.

Reply With Quote
  #2  
Old February 22nd, 2013, 02:57 PM
majlumbo majlumbo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 257 majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 9 m 16 sec
Reputation Power: 6
Without having the structure of your database, there's not much more than speculation that we can provide. Given that, is..

adotList.Append;
adotList['FixtureID'] := FixId;
adotList['OpponentID'] := OppId;
adotList['CompID'] := CompId; <-----This
adotList['FixtureDate'] := FixDate;
adotList['Venue'] := Ven;
adotList.Post;

a foreign key to

adotComp.Append;
adotComp['CompID'] := CompId; <-----This
adotComp['Competition'] := ledtCompetition.Text;
adotComp.Post;

and if so, then you need to add the record to adotComp first, so that the foreign key reference is satisfied when adding the record to adotlist...
Comments on this post
bennywilks agrees: Excellent

Reply With Quote
  #3  
Old February 22nd, 2013, 03:09 PM
bennywilks bennywilks is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 bennywilks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 22 sec
Reputation Power: 0
Yep the CompId in the 'List' Table is a Foreign Key to the 'Competition' Table.

I can't believe it was as simple as just changing the order of the code. You have saved my day. Thanks mate

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Inserting Data into Databases

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap