主题:[讨论]多条件查询示例..
procedure Tsb.BitBtn2Click(Sender: TObject);
var ed1,ed2,ed3,ed4,ed5,ed7,me1,che:string;
begin
//判断并赋值//
//1
if trim(edit1.text)<>'' then
ed1:='类别='''+trim(edit1.text)+''''
else
ed1:='1=1';
//2
if Sb.CheckBox1.Checked=true then
che:='正规=true'
else
che:='正规=false';
//3
if trim(edit2.text)<>'' then
ed2:='登记证='''+trim(edit2.text)+''''
else
ed2:='1=1';
//4
if trim(edit3.text)<>'' then
ed3:='商品名='''+trim(edit3.text)+''''
else
ed3:='1=1';
//5
if trim(edit4.text)<>'' then
ed4:='成份='''+trim(edit4.text)+''''
else
ed4:='1=1';
//6
if trim(edit5.text)<>'' then
ed5:='规格='''+trim(edit5.text)+''''
else
ed5:='1=1';
//7
if trim(edit7.text)<>'' then
ed7:='生产商='''+trim(edit7.text)+''''
else
ed7:='1=1';
//8
if trim(memo1.text)<>'' then
me1:='备注='''+trim(memo1.text)+''''
else
me1:='1=1';
Sb.ADODataSet1.Close;
Sb.ADODataSet1.CommandText:='select * from 商品 where '+ed1+' and '+che+' and '+ed5+' and '+ed2+' and '+ed3+' and '+ed4+' and '+ed7+'';
Sb.ADODataSet1.Open;
end;
var ed1,ed2,ed3,ed4,ed5,ed7,me1,che:string;
begin
//判断并赋值//
//1
if trim(edit1.text)<>'' then
ed1:='类别='''+trim(edit1.text)+''''
else
ed1:='1=1';
//2
if Sb.CheckBox1.Checked=true then
che:='正规=true'
else
che:='正规=false';
//3
if trim(edit2.text)<>'' then
ed2:='登记证='''+trim(edit2.text)+''''
else
ed2:='1=1';
//4
if trim(edit3.text)<>'' then
ed3:='商品名='''+trim(edit3.text)+''''
else
ed3:='1=1';
//5
if trim(edit4.text)<>'' then
ed4:='成份='''+trim(edit4.text)+''''
else
ed4:='1=1';
//6
if trim(edit5.text)<>'' then
ed5:='规格='''+trim(edit5.text)+''''
else
ed5:='1=1';
//7
if trim(edit7.text)<>'' then
ed7:='生产商='''+trim(edit7.text)+''''
else
ed7:='1=1';
//8
if trim(memo1.text)<>'' then
me1:='备注='''+trim(memo1.text)+''''
else
me1:='1=1';
Sb.ADODataSet1.Close;
Sb.ADODataSet1.CommandText:='select * from 商品 where '+ed1+' and '+che+' and '+ed5+' and '+ed2+' and '+ed3+' and '+ed4+' and '+ed7+'';
Sb.ADODataSet1.Open;
end;