例子如下,其中在gno是变量为什么执行SQL语句是出错,如何在TQuery组件中执行带变量SQL语句???谢谢
var
gno:string; query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select gnum from good where gno = :gno');
query1.Open;
解决方案 »
- Button = mbLeft 是什么意思?
- IDHTTP+TOMCAT引起TOMCAT内存溢出!
- 十一回家手术,这周回来的,还未完全康复,散分祝早日康复!
- 急救!!!!!!!!!!!!!!!!!!
- 关于OutLook Express的帐号和密码之难题-----就剩这点分了,很急!!!!
- 如何在Delphi里面用程序自动生成TADOConnection连接字符串?
- 急!在线等待!
- 怎样对一个DOS格式的文本文件进行操作?
- 出现"Statement expected,but expression of type'TfrxCustomPreview'found",就如何解决?
- 在DELPHI的FORM中怎样打开IE,然后让IE打开FORM送过来的URL???
- 为什么我的程序拿到用户的机器上安装,界面的样子就变了呢?
- 很奇怪的问题,进来瞧瞧……
query1.SQL.Add('select gnum from good where gno = :gno');好像是这样写的吧:
Query1.ParametersByName('gno').value=...
'select gnum from good where gno ='''+gno+''''
else if 数据库中gno字段是整形之类 then
'select gnum from good where gno = ‘+gno
给你个列子:
with query1 do
begin
close;
Sql.clear;
SQL.Add('select gnum from good where gno = :gno');
end;
query1.parambyname('gno').value;=Edit1.text(你要传给gno的值);
query1.open;
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select gnum from good where gno = :gno');
query1.sql.parambyname('gno').assring:=edit1.text; //edit1.text为where语句的参数;
query1.Open;
别忘了加分,哈哈哈哈
query1.SQL.Add('select gnum from good where gno = :gno');
gno:=edit1.text;
不同类型的话可以用:query1.sql.parambyname('gno').assTring:=edit1.text;
就可以了哦!
query1.SQL.Clear;
query1.SQL.Add('select gnum from good where gno = :gno');
query1.sql.parambyname('gno').Value:=Mygno;//注:Mygno的类型要和字段gno的类型相同
query1.Open;
query1.SQL.Clear;
query1.SQL.Add('select gnum from good where gno = :gno');
query1.sql.parambyname('gno').Value:=Mygno;//注:Mygno的类型要和字段gno的类型相同
query1.prepare;
query1.Open;query1.param[[0].astring:=xxx;