代码如下:
procedure Tf_info.cxButton1Click(Sender: TObject);
begin if (trim(cxtextedit1.Text )='') and (trim(cxtextedit2.Text )='') and
(trim(cxtextedit3.Text )='') and (trim(cxtextedit4.Text )='')
then
begin
application.MessageBox('请输入查询条件','提示',64);
cxtextedit2.SelectAll ;
cxtextedit2.SetFocus ;
exit;
end
else
begin
with DM.ADOQuery1 do
begin
close;
sql.Clear ;
sql.Add('select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where [itemid] like'+QuotedStr('%'+Trim(cxtextedit1.Text)+'%')) ;
sql.Add ( 'and [itemname] like'+QuotedStr('%'+Trim(cxtextedit2.Text)+'%') );
sql.Add( 'and [itemspecs] like'+QuotedStr('%'+Trim(cxtextedit3.Text)+'%') );
sql.Add( 'and [memo] like '+QuotedStr('%'+Trim(cxtextedit4.Text )+'%'));
dm.ADOQuery1.Active :=true;
open;
fields[0].DisplayLabel :='物料代码';//设置中文标题
fields[1].DisplayLabel :='名称';
fields[2].DisplayLabel :='规格描述';
fields[3].DisplayLabel :='单位';
fields[4].DisplayLabel :='单位';
fields[5].displaylabel :='备注';
fields[6].DisplayLabel :='创建日期';
end;
dbgrid1.Columns[0].Width :=70;//设置列宽
dbgrid1.Columns[1].Width :=110;
dbgrid1.Columns[2].Width :=200;
dbgrid1.Columns[3].Width :=40;
dbgrid1.Columns[4].Width :=60;
dbgrid1.Columns[5].Width :=90;
dbgrid1.Columns[6].Width :=100;
end;
end;
我遇到的麻烦是上面这个条件出来的结果不对,有的查不到,可数据确实有,语法也没报错
sql.Add('select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where [itemid] like'+QuotedStr('%'+Trim(cxtextedit1.Text)+'%')) ;
sql.Add ( 'and [itemname] like'+QuotedStr('%'+Trim(cxtextedit2.Text)+'%') );
sql.Add( 'and [itemspecs] like'+QuotedStr('%'+Trim(cxtextedit3.Text)+'%') );
sql.Add( 'and [memo] like '+QuotedStr('%'+Trim(cxtextedit4.Text )+'%'));
dm.ADOQuery1.Active :=true;
open;
如果把条件设一个就可以查到,四个条件中的任何一个都能查到,一起用就不行,有的存在的记录查不到
比如:
sql.Add('select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where [itemid] like'+QuotedStr('%'+Trim(cxtextedit1.Text)+'%')) ;
不知道这个什么问题?到底是哪里出现了问题?
procedure Tf_info.cxButton1Click(Sender: TObject);
begin if (trim(cxtextedit1.Text )='') and (trim(cxtextedit2.Text )='') and
(trim(cxtextedit3.Text )='') and (trim(cxtextedit4.Text )='')
then
begin
application.MessageBox('请输入查询条件','提示',64);
cxtextedit2.SelectAll ;
cxtextedit2.SetFocus ;
exit;
end
else
begin
with DM.ADOQuery1 do
begin
close;
sql.Clear ;
sql.Add('select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where [itemid] like'+QuotedStr('%'+Trim(cxtextedit1.Text)+'%')) ;
sql.Add ( 'and [itemname] like'+QuotedStr('%'+Trim(cxtextedit2.Text)+'%') );
sql.Add( 'and [itemspecs] like'+QuotedStr('%'+Trim(cxtextedit3.Text)+'%') );
sql.Add( 'and [memo] like '+QuotedStr('%'+Trim(cxtextedit4.Text )+'%'));
dm.ADOQuery1.Active :=true;
open;
fields[0].DisplayLabel :='物料代码';//设置中文标题
fields[1].DisplayLabel :='名称';
fields[2].DisplayLabel :='规格描述';
fields[3].DisplayLabel :='单位';
fields[4].DisplayLabel :='单位';
fields[5].displaylabel :='备注';
fields[6].DisplayLabel :='创建日期';
end;
dbgrid1.Columns[0].Width :=70;//设置列宽
dbgrid1.Columns[1].Width :=110;
dbgrid1.Columns[2].Width :=200;
dbgrid1.Columns[3].Width :=40;
dbgrid1.Columns[4].Width :=60;
dbgrid1.Columns[5].Width :=90;
dbgrid1.Columns[6].Width :=100;
end;
end;
我遇到的麻烦是上面这个条件出来的结果不对,有的查不到,可数据确实有,语法也没报错
sql.Add('select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where [itemid] like'+QuotedStr('%'+Trim(cxtextedit1.Text)+'%')) ;
sql.Add ( 'and [itemname] like'+QuotedStr('%'+Trim(cxtextedit2.Text)+'%') );
sql.Add( 'and [itemspecs] like'+QuotedStr('%'+Trim(cxtextedit3.Text)+'%') );
sql.Add( 'and [memo] like '+QuotedStr('%'+Trim(cxtextedit4.Text )+'%'));
dm.ADOQuery1.Active :=true;
open;
如果把条件设一个就可以查到,四个条件中的任何一个都能查到,一起用就不行,有的存在的记录查不到
比如:
sql.Add('select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where [itemid] like'+QuotedStr('%'+Trim(cxtextedit1.Text)+'%')) ;
不知道这个什么问题?到底是哪里出现了问题?
解决方案 »
- 简单的程式,海量的数据,速度问题求解!
- D不用WriteProcessMemory写内存如何写,指针?怎么写内存 ?
- 有关数据输出格式的问题
- 三层中接口参数传值的问题
- P2P之UDP穿透NAT的问题,请高手帮帮忙
- 谁有胆量接受挑战?如何更改文本数据库的内容?
- 我的打印控件!可打印stringgrid,dbgrid,datasource欢迎下哉!
- 怎样替换richedit中的一段字符?
- 如何将光标从隐藏起来,请指教。
- 关于数据库的安装
- 如何实现把一个adoquery里面的数据加入到一个adotable中(或导出到一个adoconnection中)
- 通过函数调用正确,但是通过dll调用就报错(invaild pointer operation)
如果不是这样 帖几条数据来看看
这样的程序很容易被注入~
建议过滤一些非法字符
问题出在了字段是NULL的用组合查询差不多
比如:
select * from screencode where [itemid] like '%1601%' and [memo] like '%%'
如果[Memo]字段没有值是NULL,那么用这条语句就差不出来东西对于这种问题,请教高手上面的代码得怎么个写法?
select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where itemid like '%%'
and [itemname] like'%%'
and ([itemspecs] like '%%' or itemspecs is null)
and ([memo] like '%%' or memo is null)上面的sql语句如果用在DELPHI里该怎么写?
+' and [itemname] like'+QuotedStr('%%')
+' and ([itemspecs] like '+quotedstr('%%')+' or itemspecs is null)'
+' and ([memo] like '+Quotedstr('%%')+' or memo is null) ';
close;
sql.Clear ;
sql.Add('select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where [itemid] like'+QuotedStr('%'+Trim(cxtextedit1.Text)+'%')) ;
sql.Add ( 'and isnull([itemname],'''') like'+QuotedStr('%'+Trim(cxtextedit2.Text)+'%') );
sql.Add('and isnull([itemspecs],'''') like'+QuotedStr('%'+Trim(cxtextedit3.Text)+'%')) ;
sql.Add('and isnull([memo],'''') like '+QuotedStr('%'+Trim(cxtextedit4.Text)+'%'));
dm.ADOQuery1.Active :=true;
open;