为什么我的commandtext语句加where ... 后就没有记录了呢(40分)

  • 主题发起人 主题发起人 whhzkl
  • 开始时间 开始时间
W

whhzkl

Unregistered / Unconfirmed
GUEST, unregistred user!
在我的三层结构的客户端有一个DbGrid1连着dm.CDSPntBasic(Clientdataset):
dm.CDSPntBasic.CommandText := '';
dm.CDSPntBasic.CommandText:='select * from PntBasic where replace(DEPTNAME,'+'''' + ' '+'''' + ',' + ''''+''''+') = '+''''+aaa+'''';
dm.CDSPntBasic.Execute;
dm.CDSPntBasic.Open;
dm.CDSPntBasic.Active := true;
问题是:
如果Sql语句里没有where语句,就可以返回数据集, 而加上where语句(如上)后返回为空数据集。为什么?
谢谢大家!!!!!!!!!!!!!!!!!!!!!!!!!!
 
select * from PntBasic where DEPTNAME like '''*'+aaa+'*'''
 
select * from PntBasic where DEPTNAME like '''%'+aaa+'%'''
 
'select * from PntBasic where DEPTNAME like '+ '''%'+aaa+'%'''
 
xiexie
aaa:=stringReplace(TV.Selected.Text,' ','',[rfReplaceAll]);
dm.CDSPntBasic.Close;
dm.CDSPntBasic.CommandText := '';
dm.CDSPntBasic.CommandText:='select * from PntBasic '+
'where replace(DEPTNAME,'+''''+' '+''''+','+''''+''+''''+')'+' like '+''''+aaa+'''' ;
dm.CDSPntBasic.Execute;
dm.CDSPntBasic.Open;
dm.CDSPntBasic.Active := true;
 
dm.CDSPntBasic.CommandText:='select * from PntBasic '+
'where replace(DEPTNAME,'+''''+' '+''''+','+''''+''+''''+')'+' like '+'''%'+aaa+'%''' ;
 
dm.CDSPntBasic.CommandText:='select * from PntBasic where replace(DEPTNAME,'' '','''') like '+QuotedStr('%'+aaa+'%');
 
后退
顶部