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

    Join Date
    Jun 2012
    Posts
    1
    Rep Power
    0

    [Delphi6] insert values on a database


    hello,
    i'm trying to insert some information about marck of a student in a school. But when I insert, using a DBGrid, the database create a new row!!! ok but i need to insert some information to create a relation with other table.
    This is my code to create the relation...

    Code:
    procedure TForm1.Q1BeforePost(DataSet: TDataSet);
    begin
      ADOCommand1.CommandText:=('INSERT INTO registro'+
                                   '(IdStuFk, IdMatFk, IdDocFk) '+
                                   'VALUES ('+NumIdAlunno+','+numId_Materie+','+numIdDoc+')');
      ADOCommand1.Execute;
    end;
    Ok,.... but when i insert this value into the database, the database create a new row!!!!!
    It's not correct!!!! I need to insert my information in the same row where there is the mark!!! HELP ME!!!!
    I tried to save the Mark but it is impossilbe, because there are a lot of information and are all the same(for example Rossi have six but Verdi can have the same mark)


  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    355
    Rep Power
    7
    If a blank record is being inserted into your grid, then a new record is already entered into your database waiting for you to post it.

    So in your BeforePost Method, you are again inserting a new record, which explains why you are getting a new row.

    If you need to set some values of the record before it is posted, then simply assign the columns a value, i.e.
    Code:
    procedure TForm1.Q1BeforePost(DataSet: TDataSet);
    begin
       ADOQuery1ColumnName.AsString := 'This is my new value';
    end;
    and let the post proceed. You do not want to issue yet another SQL Insert command.

IMN logo majestic logo threadwatch logo seochat tools logo