我编写一个本地查询,数据保存成本地cds格式。我用的是以下格式: if edtName.Text<>'' then
lsWhere := lsWhere + ' and NAME like ''%'+ trim(edtName.Text)+'%'''; cdsCustomer.Filter := lsWhere ;
cdsCustomer.Filtered :=true;
如果我用姓名的全部内容,如edtName填写“王大名” 就查不到记录,如查询“王大”就可以查询到“王大名”这条记录。我太奇怪了,有没有碰到过这样的问题,help me
lsWhere := lsWhere + ' and NAME like ''%'+ trim(edtName.Text)+'%'''; cdsCustomer.Filter := lsWhere ;
cdsCustomer.Filtered :=true;
如果我用姓名的全部内容,如edtName填写“王大名” 就查不到记录,如查询“王大”就可以查询到“王大名”这条记录。我太奇怪了,有没有碰到过这样的问题,help me
lsWhere := lsWhere + ' and NAME='''+ trim(edtName.Text)+'*''';
这样只支持后边的模糊查找,但不支持中间的模糊查找和前面的模糊查找,
如果你要想都支持,就要在下面的事件中写:
table1.filtered:=true;//设置使打开。
table1.close;
table1.open;table1.onFilterRecord中加入以下代码:
begin
with table1 do
begin
if fieldByName('myField').asString= trim(edtName.Text) then
accept:=true
else
accept:=false;
end;
end;
--这种写法错,楼主的写法是正确的。
过滤本身就不支持like的‘%’这种说法
--支持建议你看一下ClientDataSet的filteroptions属性设置(应该跟这各无关),另外就是Param属性是否用相关设置导致
lsWhere := lsWhere + ' and NAME like ''%'+ trim(edtName.Text)+'*'''; cdsCustomer.Filter := lsWhere ;
cdsCustomer.Filtered :=true;