'aq是一个AdoQuery控件
sql:='select skills_index from prg_skills where skills_title=p1';
aq.SQL.Clear;
aq.SQL.Add(sql);
aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;'程序运行到这一行出错
aq.Open;
出错信息:
Aq:Parameter 'p1' not found.
这是怎么回事啊?我在设计阶段为aq添加了参数(Parameters属性)没有任何作用,出现相同的错误。
如果aq没有参数,怎样给它添加参数啊?
sql:='select skills_index from prg_skills where skills_title=p1';
aq.SQL.Clear;
aq.SQL.Add(sql);
aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;'程序运行到这一行出错
aq.Open;
出错信息:
Aq:Parameter 'p1' not found.
这是怎么回事啊?我在设计阶段为aq添加了参数(Parameters属性)没有任何作用,出现相同的错误。
如果aq没有参数,怎样给它添加参数啊?
aq.SQL.Clear;
aq.SQL.Add(sql);
aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;
aq.Open;
sql:='select skills_index from prg_skills where skills_title=:p1';
..........
aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;'方法二:
sql:='select skills_index from prg_skills where skills_title='+txttitle.text;
.................
后面什么都不加了。
是:
aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;'
这句话就不写了。
1 sql:='select skills_index from prg_skills where skills_title=p1';
2 aq.SQL.Clear;
3 aq.SQL.Add(sql);
4 aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;'程序运行到这一行出错
5 aq.Open;帮你减少几行代码.
1 aq.sql.text:='select skills_index from prg_skills where skills_title='+txttitle.text;
2 aq.open;
当然你最好是在OPEN的时候加上异常处理:
try
aq.open;
...
except
showmessage('连接失败!');
....
end;
aq.close;
aq.SQL.Clear;
aq.SQL.Add(sql);
aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;
aq.Open;