Page 1 of 1

Probleme with insert command

Posted: Wed 19 Sep 2007 09:00
by rvzip64
Hi everybody

I use the trial version of Mydac and i have a problem with an insert query.

On my form i have a Myquery component with these:

Code: Select all

select id1,id2 from DB1.Table1 where id1=4 and id2=1
(i know the query is stupid but it's for the example)


after i have a mycommand component with these:

Code: Select all

 insert into DB1.Table2 (id1,Id2,NumLot) values (:Id1,:Id2,'BBB')

The probleme is, when i try to execute the sql insert , i have an error
" 'id1' cannot be null "

Sorry for my bad english.

Posted: Wed 19 Sep 2007 09:23
by Antaeus
Did you assigned parameters of TMyCommand before executing? It should look like this:

Code: Select all

  MyCommand.ParamByName('Id1').AsInteger := 1;
  MyCommand.ParamByName('Id2').AsInteger := 2;

Posted: Wed 19 Sep 2007 09:25
by rvzip64
No because, i would like to use the result of myquery

Posted: Wed 19 Sep 2007 13:10
by rvzip64
Do you have an idea ?

Posted: Wed 19 Sep 2007 13:38
by Antaeus
If you want to insert a single record, you should assign parameters in this way before execution:

Code: Select all

  MyCommand.ParamByName('Id1').AsInteger := MyQuery.ParamByName('Id1').AsInteger;
  MyCommand.ParamByName('Id2').AsInteger := MyQuery.ParamByName('Id2').AsInteger;
If you want to load all records from Table1 into Table2, you can either use TCRBatchMove component, or TMyLoader with its LoadFromDataSet method.
For more information read the MyDAC help.