#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep 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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    354
    Rep Power
    7
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep 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

IMN logo majestic logo threadwatch logo seochat tools logo