读书人

50分! 请大家告诉,这段语句错在哪里?

发布时间: 2012-02-29 16:44:10 作者: rapoo

50分!!! 请大家告诉,这段语句错在哪里?
按条件的查询:


我想按条件查询数据库里的信息,其中字段CODE 里保存的七位数字的阿拉伯数字.

比如 1100718 /1100788 /1209810 /1351234 ,

我想达到的要求是只输入前三位的数字比如 110 即可查询出相应的数据 1100718 /1100788


以下是原语句,任何问题都没有,但不是我想要的模糊查询...........


----------------------------------------------------;


procedure TSarch.BitBtn7Click(Sender: TObject);
var ss:string;
var mStr1:string;
var low1,high1:string;
begin
mStr1 := 'select * from information where ';


ss := ' ';

if Rzcombobox6.Text <> ' ' then
ss:=ss+ 'model= ' ' '+Rzcombobox6.Text+ ' ' ' and ';


// 部件代码查询

if Edit7.Text <> ' ' then
ss:=ss+ 'code = ' ' '+Edit7.Text+ ' ' ' and ';


if Rzcombobox7.Text <> ' ' then
ss:=ss+ 'shift= ' ' '+Rzcombobox7.Text+ ' ' ' and ';

if Rzcombobox8.Text <> ' ' then
ss:=ss+ 'line= ' ' '+Rzcombobox8.Text+ ' ' ' and ';

if Rzcombobox9.Text <> ' ' then
ss:=ss+ 'grade= ' ' '+Rzcombobox9.Text+ ' ' ' and ';


low1:=formatdatetime( 'yyyy-mm-dd ',DateTimePicker4.Date);
high1:=formatdatetime( 'yyyy-mm-dd ',DateTimePicker5.Date);
ss:=mStr1 + ss + 'workdate <=# '+high1+ '# and workdate> =# '+low1+ '# ' + 'order by id desc ' ;


ADOQuery4.Connection:=ADOConnection1;
ADOQuery4.Close;
ADOQuery4.SQL.Clear;
ADOQuery4.SQL.Add(ss);
ADOQuery4.Open;

end;


end.

----------------------------


但是我改成下面这样,为什么运行不了? 错在哪里????请指点.....谢谢!!!!!!


...........................................................


// 部件代码查询

if Edit7.Text <> ' ' then
ss:=ss+ 'code like= ' ' '+Edit7.Text+ ' ' ' and ';

..............................................................




[解决办法]
if Edit7.Text <> ' ' then
ss := ss + 'code like ' '% ' + Edit7.Text + '% ' ' and ';

------解决方案--------------------


模糊查询
SQL:
if Edit7.Text <> ' ' then
ss := ss + 'code like ' '% ' + Edit7.Text + '% ' ' and ';
Access:
if Edit7.Text <> ' ' then
ss := ss + 'code like ' '* ' + Edit7.Text + '* ' ' and ';
[解决办法]
if Edit7.Text <> ' ' then
ss := ss + 'code like ' ' ' + Edit7.Text + '% ' ' and ';

读书人网 >.NET

热点推荐