ADODataSet.CommandText的问题(50分)

  • 主题发起人 主题发起人 tswhq
  • 开始时间 开始时间
T

tswhq

Unregistered / Unconfirmed
GUEST, unregistred user!
OtherData.CommandText :='Select * From CurrentData Where OPERATE="'+p.User_ID+'" and BYZD not like ''%1%'' and BYZD not like ''%0%''';
想筛选出指定员工号、BYZD 不包含 1和0 的记录
但返回总是空记录,请大家帮忙。
BYZD not like ''%1%'' and BYZD not like ''%0%''' 主要是这部分有问题
 
是不是用单引号不对呀?字符串不是用了两个连续的单引号表示一个单引号吗?
 
你能不能把部分括一下啊。
 
是双引号不对,Operate="'+p.user_Id+'"这一部分,都改成单引号,如下:
OtherData.CommandText :='Select * From CurrentData Where OPERATE='''+p.User_ID+''' and BYZD not like ''%1%'' and BYZD not like ''%0%''';
 
to HunterTeam
以前的语句就是OtherData.CommandText :='Select * From CurrentData Where OPERATE="'+p.User_ID+'"' 没有问题
不过试过你的方法了,问题依旧.
期盼中................
 
或许是应该用括号括一下,比较不容易出错:
OtherData.CommandText :='Select * From CurrentData Where OPERATE='''+p.User_ID+''' and (not (BYZD like ''%1%'')) and (not (BYZD like ''%0%''))';
 
OtherData.CommandText :='Select * From CurrentData Where OPERATE="'+p.User_ID+'" and BYZD not like ''%1%'' and BYZD not like ''%0%''';
不知道你的p.user_ID是什么,是字段名吗?如果是串应该报错啊。如果是字段名,还能OPERATE的值=字段名?
 
to HunterTeam

OtherData.CommandText :='Select * From CurrentData Where OPERATE='''+p.User_ID+''' and (not (BYZD like ''%1%'')) and (not (BYZD like ''%0%''))'; 不行呀


to newmoonfaw
p.User_ID是指针指向的结构变量,UUser_ID是String;
 
OtherData.CommandText :='Select * From CurrentData Where OPERATE='''+p.User_ID+'''';可以用
// and (BYZD not like ''%1%'') and (BYZD not like ''%0%'') ';
 
分成两句,先分别测一下,就容易找原因了:
OtherData.CommandText :='Select * From CurrentData Where OPERATE='''+p.User_ID+''' and (not (BYZD like ''%1%''))' ;
OtherData.CommandText :='Select * From CurrentData Where OPERATE='''+p.User_ID+''' and (not (BYZD like ''%0%''))' ;
 
承蒙各位帮助,问题解决,开心死了,方法是:
OtherData.CommandText :='Select * From CurrentData Where (BYZD not like ''%1%'') and (BYZD not like ''%0%'') and OPERATE='''+p.User_ID+''' ';
 
多人接受答案了。
 
后退
顶部