愿意是:
with query1 do
begin
close;
sql.Clear ;
unprepare ;
s:='update animals set name='''+edit2.text+''''+
'where name='''+edit1.text+'''';
sql.add(s);
prepare ;
execsql;
end;我想用参数实现。以下代码运行通过:
.......(省略)
s:='update animals set name='''+edit2.text+''''+
'where name=:q';
parambyname('q').asString:=edit1.text;
.......(省略)但下面的代码却运行错误:
.......(省略)
s:='update animals set name=:q'+
'where name='''+edit1.text+'''';
parambyname('q').asString:=edit2.text;
.......(省略)提示:parameter'q' not found-------------
edit1.text和edit2.text都是字符串类型阿.难道set和where各有玄机?
请指教。
with query1 do
begin
close;
sql.Clear ;
unprepare ;
s:='update animals set name='''+edit2.text+''''+
'where name='''+edit1.text+'''';
sql.add(s);
prepare ;
execsql;
end;我想用参数实现。以下代码运行通过:
.......(省略)
s:='update animals set name='''+edit2.text+''''+
'where name=:q';
parambyname('q').asString:=edit1.text;
.......(省略)但下面的代码却运行错误:
.......(省略)
s:='update animals set name=:q'+
'where name='''+edit1.text+'''';
parambyname('q').asString:=edit2.text;
.......(省略)提示:parameter'q' not found-------------
edit1.text和edit2.text都是字符串类型阿.难道set和where各有玄机?
请指教。
而且有一种可能是你QUERY没有设置Connection属性
而且有一种可能是你QUERY没有设置Connection属性--------------------------------------
1。Parameters.ParamByName('a').Value:=edit1.text;。这句语法错误
2。query并没有connection属性需要说明的是,我用的是bde组件的Query控件
你确认数据连接已打开,参数应该是没问题的
你确认数据连接已打开,参数应该是没问题的
-----------------------------
确认无误。
只是程序运行时抛出异常:
Query1 parameter 'q' not found
修改为:
sql.add('update animals set name=:q1'
+' where name=:q2');
Parambyname('q1').AsString :=edit2.text;
Parambyname('q2').AsString :=edit1.text;就是where前面加一个空格