查询(22分)

  • 主题发起人 主题发起人 D影子D
  • 开始时间 开始时间
D

D影子D

Unregistered / Unconfirmed
GUEST, unregistred user!
var
namestr:string;
begin
namestr:=edit1.text;//字段内容;
query1.close;
query1.sql.clear;
query1.sql.add('select * from f:/表1.dbf where (name>=:n1) and (name<=:n2)');
query1.paramsbyname('n1').asstring:=namestr+chr(0);
query1.paramsbyname('n2').asstring:=namestr+chr(255);
query1.open;
end;
出现无效关键字错误
 
query1.paramsbyname('n2').asstring:=namestr+chr($0);
query1.paramsbyname('n2').asstring:=namestr+chr($255);
 
这想是这一句有问题。
query1.sql.add('select * from f:/表1.dbf where (name>=:n1) and (name<=:n2)');
会不会把':/表1'当成了变量?
 
改为
query1.sql.add('select * from "f:/表1.dbf" where (name>=:n1) and (name<=:n2)');
 
這樣試試:
query1.sql.add('select * from ''f:/表1.dbf'' where (name>=:n1) and (name<=:n2)');
在f:/表1.dbf兩邊各加二個單引號
 
可是不能怎么知道结果?谁能给个模糊查询的例子?
email:wcdxyl@chinaren.com
 
说说你想要得到的记录,字符型一般用LIKE比较多。:)
 
就是一般的字符吧
 
var
i,j:integer;
ybqh:Tybqh;
keytodq:array of string;
listitem:Tlistitem;
begin
setlength(keytodq,maxkey+1);
if trim(edit1.text)='' then
begin
showmessage('请输入关键字!');
exit;
end;
for i:=0 to treeview1.Items.Count -1 do
begin
j:=integer(treeview1.Items.Data^);
keytodq[j]:=treeview1.Items.Text;
end;
listview1.Items.BeginUpdate ;
listview1.Items.Clear ;
j:=0;
sfile.Position :=datapos;
while sfile.Read(ybqh,sizeof(Tybqh))>0 do
begin
if ybqh.key <0 then continue;
if (mh.Checked and ((ckdqmc.Checked and (ansipos(edit1.text,ybqh.mc)>0))
or (ckdqpy.Checked and (pos(uppercase(edit1.text),getpy(ybqh.mc))>0))
or (ckyzbm.Checked and (pos(edit1.text,ybqh.yb )>0))
or (ckdhqh.Checked and (pos(edit1.text,ybqh.qh)>0))))
or (jq.Checked and ((ckdqmc.Checked and (edit1.text=ybqh.mc))
or (ckdqpy.Checked and (uppercase(edit1.text)=getpy(ybqh.mc)))
or (ckyzbm.Checked and (edit1.text=ybqh.yb ))
or (ckdhqh.Checked and (edit1.text=ybqh.qh))))
then
begin
j:=j+1;
listitem:=listview1.Items.Add ;
listitem.caption:=keytodq[ybqh.key];
listitem.SubItems.Add(ybqh.mc);
listitem.SubItems.Add(ybqh.qh);
listitem.SubItems.Add(ybqh.yb);
listitem.Data:=new(Pkey);
integer(listitem.data^):=sfile.Position -sizeof(Tybqh);
end;
end;
columntosort:=2;
order:=-1;
listview1.AlphaSort ;
listview1.Items.EndUpdate ;
statusbar1.Panels [1].Text :='共'+inttostr(j)+'个';

-------------
上面是一个例子,里面有两个单选框,4个多选框。
JQ和MH是两个单选框,代表精确查询和模糊查询
另四个为CKDQMC,CKDQPY,CKYZBM,CKDHQH ,这四个
字段为你所要查询的字段
ybqh这个是数据库,其他的我也就不解释了,自己看吧
-----------
 
多人接受答案了。
 

Similar threads

后退
顶部