如何将参数传递给ADOQuery对象?

时间:2020-12-15 11:15:06

I am using ADOQuery in Delphi 7 and Oracle. I am getting error while passing parameters to ADOQuery. I have used following line. Please help me to identify error.

我在Delphi 7和Oracle中使用ADOQuery。我在将参数传递给ADOQuery时出错。我用的是下面这一行。请帮助我识别错误。

ADOQuery.Sql.text:= 'select * from temp_table '+
        'where column1 in (select column from table2 where id=:id) and id=:id';
ADOQuery.Parameters.ParamByValue('id').value= 'abc';
ADOQuery.open;

when I open the query i will get following error:

当我打开查询时,我会得到以下错误:

Parameter object is improperly defined. Inconsistent or incomplete information is provided.

参数对象定义不正确。提供不一致或不完整的信息。

3 个解决方案

#1


4  

We have the same problem, we ended "masking" the class TParameters like this:

我们有同样的问题,我们结束了像这样“屏蔽”类TParameters:

Declaration:

声明:

TMyParameter = class(TParameter)
private
  function GetAsValue: variant;
  Procedure SetAsValue(const Value: variant);
public
  property Value: variant read GetAsValue write SetAsValue;
end;

Implementation:

实现:

procedure TMyParameter.SetAsValue(const Value: variant);
var
  iPar: Integer;

begin
  for iPar:= 0 to Collection.Count - 1 do
    if (Name = TParameter(Collection.Items[iPar]).Name) then
      TParameter(Collection.Items[iPar]).Value:= Value;
end;

function TMyParameter.GetAsValue: variant;
begin
  Result:= inherited Value;
end;

And how to use:

以及如何使用:

TMyParameter(ADOQuery.Parameters.ParamByName('id')).AsValue:= 'abc';

I hope it helps.

我希望它有帮助。

#2


1  

for i:=0 to ADOQuery.Parameters.Count-1 do
begin
  if ADOQuery.Parameters.Items[i].Name = 'id' then
    ADOQuery.Parameters.Items[i].Value := 'abc';
end;

#3


0  

You need to distinguish between the two id;s:

您需要区分这两个id;

ADOQuery.Sql.text:= 'select * from temp_table a where column1 in (select column from table2 b where b.id=:id) and a.id=:id'; 
ADOQuery.Parameters.ParamByValue('id').value= 'abc'; 
ADOQuery.open;

#1


4  

We have the same problem, we ended "masking" the class TParameters like this:

我们有同样的问题,我们结束了像这样“屏蔽”类TParameters:

Declaration:

声明:

TMyParameter = class(TParameter)
private
  function GetAsValue: variant;
  Procedure SetAsValue(const Value: variant);
public
  property Value: variant read GetAsValue write SetAsValue;
end;

Implementation:

实现:

procedure TMyParameter.SetAsValue(const Value: variant);
var
  iPar: Integer;

begin
  for iPar:= 0 to Collection.Count - 1 do
    if (Name = TParameter(Collection.Items[iPar]).Name) then
      TParameter(Collection.Items[iPar]).Value:= Value;
end;

function TMyParameter.GetAsValue: variant;
begin
  Result:= inherited Value;
end;

And how to use:

以及如何使用:

TMyParameter(ADOQuery.Parameters.ParamByName('id')).AsValue:= 'abc';

I hope it helps.

我希望它有帮助。

#2


1  

for i:=0 to ADOQuery.Parameters.Count-1 do
begin
  if ADOQuery.Parameters.Items[i].Name = 'id' then
    ADOQuery.Parameters.Items[i].Value := 'abc';
end;

#3


0  

You need to distinguish between the two id;s:

您需要区分这两个id;

ADOQuery.Sql.text:= 'select * from temp_table a where column1 in (select column from table2 b where b.id=:id) and a.id=:id'; 
ADOQuery.Parameters.ParamByValue('id').value= 'abc'; 
ADOQuery.open;