关于查询的问题,各位请进(10分)

S

studing

Unregistered / Unconfirmed
GUEST, unregistred user!
运行查询语句时,提示1:inalid field name.asql 点确定后提示:project proyect2.exe raised
exception class edbengine error with message 'invalid field name asql',process stopped
use setp or run to continue;
程序如下(请高手指点错误)
procedue tfrm_search.button1click(sender,tobject);
var
asql:string;
begin
if combobox1.text<>'' then asql:='and (编号:="'+combobox1.text+'")';
if combobox2.text<>'' then asql:=asql+'and(姓名:="'+combobox2.text+'")'
with frn_wirder do
begin
query1.close;
query1.sql.text:='select * from 人员信息.db where asql'(不知道where语句用的对不对);
datasource1.dataset:=query1;
query1.open;
end;
close;
end;
end.
 
where 后面没有条件怎么接 and 呀!
你弄错了!
 
if combobox1.text<>'' then asql:='(编号:="'+combobox1.text+'")';
 
where 1=1 '+asql 然后把后面加上就可以了,注意有空格
 
跟踪一下 看看你的SQL字符串对不对呀,基本的方法。唉
 
where 后面是不能直接加 and 的
 
:=
——》
=
 
procedue tfrm_search.button1click(sender,tobject);
var
asql:string;
begin
asql='';
if combobox1.text<>'' then asql:='(编号='+QuotedStr(combobox1.text);
if combobox2.text<>'' then
if asql<>'' then
asql:=asql+' and 姓名='+QuotedStr(combobox2.text)
else
asql='姓名='+QuotedStr(combobox2.text)';
with frn_wirder do
begin
query1.close;
query1.sql.text:='select * from 人员信息.db where ' + asql(不知道where语句用的对不对);
datasource1.dataset:=query1;
query1.open;
end;
close;
end;
 
procedue tfrm_search.button1click(sender,tobject);
var
asql:string;
begin
asql:='';
if combobox1.text<>'' then asql:='(编号='''+combobox1.text+''')';

if combobox2.text<>'' then
asql:=asql+'and (姓名='''+combobox2.text+''')'
else
asql:='(姓名='''+combobox2.text+''')';

with frn_wirder do
begin
query1.close;
query1.sql.text:='select * from 人员信息.db where '+asql;
datasource1.dataset:=query1;
query1.open;
end;
close;
end;
end.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
650
import
I
顶部