3

I am using TQuery to insert record into table. Below is the code for that.

with qryABC do
    begin
      Close;
      SQL.Clear;
      SQL.Text := 'INSERT INTO tableXYZ (ID) values (:ID)';
      ParamByName('ID').Value := AnyID;
      ExecSQL;
      Close;
    end;

When I fire same query from oracle, query gets fired, but giving exception when I try to fire the query from delphi xe2. While debugging, I found out that I get error on "ExecSQL" statement in above code. Exception is: EDBEngineError - Operation Not Applicable

I googled it but with no fruit. Please help.

  • 1
    `SQL.Clear` is redundant here. It is used when instead of `SQL.Text := s1 + s2` one prefers `SQL.Clear; SQL.Add(s1); SQL.Add(s2);` – Arioch 'The Dec 04 '12 at 09:15
  • BDE is loooong deprecated. It was deprecated even in old non-Unicode Delphi, and today it is even worse. Did you try any up to date connectivity ? AnyDAC or UniDAC or Delphi DB-Express or ADO at least ? Really, don't mess with BDE today if u can avoid it. This deprecation is one of reasons why u can google nothing - no one cares today opf that ancient leftover. Oh, and BTW - is the transaction started ? – Arioch 'The Dec 04 '12 at 09:16
  • 2
    1) What is `AnyID` ? show datatype declaration and value assigned. 2) Don't use `.Value`, try `ParamByName('ID').AsInteger` or `ParamByName('ID').AsString` or what u actually need parameter to be. – Arioch 'The Dec 04 '12 at 09:17
  • @Arioch'The - Thanks buddy, your suggestion has done my job. I was using .Value for every parameter I was passing, but when I changed it to integer, it worked. Thanks again for saving my day :) –  Dec 04 '12 at 09:25
  • 2
    Glad it helped. But i still suggest you to ditch BDE as fast as u can. – Arioch 'The Dec 04 '12 at 10:08

1 Answers1

2

What is AnyID ? With questions like this better to show datatype declaration and value assigned.

As a general suggestion - don't use .Value, try ParamByName('ID').AsInteger or ParamByName('ID').AsString or what u actually need that certain parameter to be.

Not only that would be faster but it also produces more determinate code with compile-time type checking, rather than significantly slower and much less predictable runtime dynamic Variant datatype conversions.

This applies to Fields as well as too Parameters.

Arioch 'The
  • 15,799
  • 35
  • 62