用ADO查询sql explor中的数据总是提示“不正常地定义参数对象,提供的参数信息不完整”
ADO中定义了id,xmzj两个参数为String型,代码:
StrSql := 'Select * from table1 where ';
if RBtn_Xmbh.Checked then
begin
StrSql := StrSql+'id=:id';
ADOQuery1.Parameters.ParamByName('id').Value :=EDname.Text;
end;
if RBtn_Xmzj.Checked then
begin
StrSql := StrSql+'cost=:xmzj';
ADOQuery1.Parameters.ParamByName('xmzj').Value :=EDname.Text;
end; ADOQuery1.Close;
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add(StrSql);不知何解?
ADO中定义了id,xmzj两个参数为String型,代码:
StrSql := 'Select * from table1 where ';
if RBtn_Xmbh.Checked then
begin
StrSql := StrSql+'id=:id';
ADOQuery1.Parameters.ParamByName('id').Value :=EDname.Text;
end;
if RBtn_Xmzj.Checked then
begin
StrSql := StrSql+'cost=:xmzj';
ADOQuery1.Parameters.ParamByName('xmzj').Value :=EDname.Text;
end; ADOQuery1.Close;
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add(StrSql);不知何解?
解决方案 »
- 如何使modal窗口不被挡住
- delphi7制作一个条形码。。。
- 求助,如何在ListView或ShellListView中加入并关联文件及其图标?
- 我在安装FastReport的时候提示:fs_ipascal.pas找不到
- 多线程串口通信的奇怪问题(主线程进行大数据量的操作会丢失部分串口返回的数据,否则一切正常),请高手帮忙!!!!!
- 怎样才能把窗体的变量值转入已做好的报表中的memo中呢? 是fastreport报表。急急!!!
- 刚参加完CSDN的第六次技术论谈,感觉实在是有点…………… (内详)
- 请教一个简单的图形算法
- delphi2009 datasnap多层结构,如何知道服务端的class是被哪个客户端调用的?
- 程序中途退出用何函数
- 定时读取数据的程序,取不到最新的数据??
- 求一条语句 library path
StrSql := 'Select * from table1';
这样改试试,
ADO中定义了id,xmzj两个参数为String型,代码:
定义一个变量表示已加入过条件
StrSql := 'Select * from table1 ';
k := True; if RBtn_Xmbh.Checked then
begin
if k = true then
begin
StrSql := StrSql+' WHERE ';
StrSql := StrSql+'id=:id';
k = false;
end else
StrSql := StrSql + 'and id=:id '; ADOQuery1.Parameters.ParamByName('id').Value :=EDname.Text;
end;
if RBtn_Xmzj.Checked then
begin
if k = true then
begin
StrSql := StrSql+' WHERE ';
StrSql := StrSql+'cost=:xmzj';
k = false;
end else
StrSql := StrSql+'cost=:xmzj';
ADOQuery1.Parameters.ParamByName('xmzj').Value :=EDname.Text;
end; ADOQuery1.Close;
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add(StrSql);
StrSql := StrSql+'cost=:xmzj';
应该改为
end else
StrSql := StrSql+'and cost=:xmzj ';
StrSql := StrSql+' and cost=:xmzj ';and前也不能少空格。
ADOQuery1.Parameters.ParamByName('id').Value :=EDname.Text;
这句应该放在
ADOQuery1.SQL.Add(StrSql);后面