R
richard0922
Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:<br>procedure Tf_info.cxButton1Click(Sender: TObject);<br>begin<br><br> if (trim(cxtextedit1.Text ='') and (trim(cxtextedit2.Text ='') and<br> (trim(cxtextedit3.Text ='') and (trim(cxtextedit4.Text ='')<br> then<br> begin<br> application.MessageBox('请输入查询条件','提示',64);<br> cxtextedit2.SelectAll ;<br> cxtextedit2.SetFocus ;<br> exit;<br> end<br> else<br> begin<br> with DM.ADOQuery1 do<br> begin<br> close;<br> sql.Clear ;<br> sql.Add('select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where [itemid] like'+QuotedStr('%'+Trim(cxtextedit1.Text)+'%')) ;<br> sql.Add ( 'and [itemname] like'+QuotedStr('%'+Trim(cxtextedit2.Text)+'%') <br> sql.Add( 'and [itemspecs] like'+QuotedStr('%'+Trim(cxtextedit3.Text)+'%') <br> sql.Add( 'and [memo] like '+QuotedStr('%'+Trim(cxtextedit4.Text +'%'));<br> dm.ADOQuery1.Active :=true;<br> open;<br><br> <br> fields[0].DisplayLabel :='物料代码';//设置中文标题<br> fields[1].DisplayLabel :='名称';<br> fields[2].DisplayLabel :='规格描述';<br> fields[3].DisplayLabel :='单位';<br> fields[4].DisplayLabel :='单位';<br> fields[5].displaylabel :='备注';<br> fields[6].DisplayLabel :='创建日期';<br> end;<br> dbgrid1.Columns[0].Width :=70;//设置列宽<br> dbgrid1.Columns[1].Width :=110;<br> dbgrid1.Columns[2].Width :=200;<br> dbgrid1.Columns[3].Width :=40;<br> dbgrid1.Columns[4].Width :=60;<br> dbgrid1.Columns[5].Width :=90;<br> dbgrid1.Columns[6].Width :=100;<br><br> end;<br><br>end;<br>我遇到的麻烦是上面这个条件出来的结果不对,有的查不到,可数据确实有,语言也没报错<br> sql.Add('select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where [itemid] like'+QuotedStr('%'+Trim(cxtextedit1.Text)+'%')) ;<br> sql.Add ( 'and [itemname] like'+QuotedStr('%'+Trim(cxtextedit2.Text)+'%') <br> sql.Add( 'and [itemspecs] like'+QuotedStr('%'+Trim(cxtextedit3.Text)+'%') <br> sql.Add( 'and [memo] like '+QuotedStr('%'+Trim(cxtextedit4.Text +'%'));<br> dm.ADOQuery1.Active :=true;<br> open;<br>如果把条件设一个就可以查到,四个条件中的任何一个都能查到<br>比如:<br>sql.Add('select [itemid],[itemname],[itemspecs],[itemunit],[category],[memo],[date] from itemaccoun where [itemid] like'+QuotedStr('%'+Trim(cxtextedit1.Text)+'%')) ;<br>不知道这个什么问题?到底是哪里出现了问题?