Delphi 中 adoquery Parameter ‘A’ not found---------半转

来源:互联网 发布:大数据时代的变革 编辑:程序博客网 时间:2024/06/04 21:06

问:adoquery Parameter ‘A’ not found
源码为:

1
2
3
4
5
6
7
8
9
10
11
    Query2.Close;
    Query2.SQL.Clear;
    Query2.SQL.Add('select * From mnyCheckMonth');
    Query2.SQL.Add('where mcmCheckId in(Select DisTinCt msmCheckId From
mnyServeMonth');
    Query2.SQL.Add('Where msmTableId in (Select btaId From basTable');
    Query2.SQL.Add('Where btaDepartment=:A))');
    Query2.Parameters.ParamByName('A').Value := List[0].Text;//参数[0]也就
是A的值为中文'服务1部'
    //Query2.Parameters.Parameter.Value := List[0].Text;
    Query2.Open;

答:因为参数A取到了中文值,而Delphi 7的TADOQuery组件毕竟不是ADO原生控件,所
以在传递中文方面存在BUG,所以当Query2的ParamCheck打开为True的时候,中文参数
值会变成乱码,所以造成参数的自动构建失败。所以出现错误:Parameter ‘A’ not
found。
相比而言,BDE的组件TQuery毕竟是Borland的原生控件,在中文参数值传递方面暂时
未发现BUG。
另外还有一个原因,就是当设置主从数据表关系时,动态读取从表数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
procedureTDataModule1.ds_customerDataChange(Sender: TObject;
  Field: TField);
var
  CustomerId:Variant;
begin
  try
    CustomerId:=qry_customer.FieldValues['id'];
    qry_yinban.Close;
    qry_yinban.SQL.Clear;
    qry_yinban.SQL.Add('SELECT * FROM yinban WHERE customer_id=:CustomerId');
    qry_yinban.Parameters.ParseSQL(qry_yinban.SQL.Text,True);
    qry_yinban.Parameters.ParamByName('CustomerId').Value:=CustomerId;
    qry_yinban.Open;
  except
  end;
end;

解决方面是:关闭ParamCheck为False,这样中文参数传递正确,然后使用
Query2.Parameters.ParseSQL(Query2.SQL.Text, true);强制生成参数对象。

 以上为转载,但在实际中我的解决正好相反,是把ParamCheck 属性 设为 True!!  不解...

原创粉丝点击