Probleme with insert command

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
rvzip64
Posts: 17
Joined: Wed 19 Sep 2007 08:51

Probleme with insert command

Post by rvzip64 » Wed 19 Sep 2007 09:00

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.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 19 Sep 2007 09:23

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;

rvzip64
Posts: 17
Joined: Wed 19 Sep 2007 08:51

Post by rvzip64 » Wed 19 Sep 2007 09:25

No because, i would like to use the result of myquery

rvzip64
Posts: 17
Joined: Wed 19 Sep 2007 08:51

Post by rvzip64 » Wed 19 Sep 2007 13:10

Do you have an idea ?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 19 Sep 2007 13:38

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.

Post Reply