A
A
alex1233211232016-05-18 09:54:01
Delphi
alex123321123, 2016-05-18 09:54:01

Problem with TADOCommand in Delphi?

The first time you run the current code, everything is in order, when you use it again, an error occurs - there is no G1 parameter.
ADOCommand1.CommandText := 'delete from [Test] where GUID = :G1';
ADOCommand1.ParamCheck := False;
ADOCommand1.Parameters.ParamByName('G1').Value := guid;
ADOCommand1.Execute();
What could be the problem?
Upd(!): more precisely, the problem occurs if you use ADOCommand1 for another command, and then try to use the current one again.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kileev, 2016-05-18
@alex123321123

ADOCommand has parameters from the previous command, but not from the new one.
If ADOCommand1 is created dynamically, then you need to do:

ADOCommand1.CommandText := 'delete from [Test] where GUID = :G1';
ADOCommand1.Parameters.Clear;
ADOCommand1.Parameters.ParseSQL(ADOCommand1.CommandText, True);
ADOCommand1.Parameters.ParamByName('G1').Value := guid;
ADOCommand1.Execute();

If ADOCommand1 lies on the form, then for each command it is necessary to put a separate TADOCommand on the form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question