string strwhere = "";
sdc.cleardatabinding(this);//清掉绑定源
if(!string.IsNullOrEmpty(bstcode.Text))
strwhere+="a.stcode like '%"+bstcode.Text+"%' and ";
if(!string.IsNullOrEmpty(bstlea.Text))
strwhere+="a.stlec like '%"+bstlea.Text+"%' and ";
if(!string.IsNullOrEmpty(comboBox1.Text))
strwhere+="a.stlea like '"+comboBox1.SelectedValue.ToString()+"' and ";//以真实值做为查询条件
if(!string.IsNullOrEmpty(bstlec.Text))
strwhere+="a.stleb like '%"+bstlec.Text+"%' and ";
if(!string.IsNullOrEmpty(bre1.Text))
strwhere+="a.re1 like '%"+bre1.Text+"%' and ";
if(!string.IsNullOrEmpty(bdec1.Text))
strwhere+="a.stled like '%"+bdec1.Text+"%' and ";
if (strwhere.Length > 1)
{
strwhere = "select a.*,b.str2 as dddd from Epurchase a left join Evendor b on a.stlea = b.codestr where " + strwhere.Substring(0, strwhere.Length - 5) + ";" +
"select b.*,c.ccomunitname,convert(varchar(100),datea,23) as dateaa from Epurchase a left join Epurchaseson b on a.stcode=b.stcode left join Ainventory c on b.cinvcode = c.cinvcode where " + strwhere.Substring(0, strwhere.Length - 5);
dsaa = sdc.ads(strwhere);//生成datatable
我老是如上写查询语句,但当条件多的时候,就涉及更多,有没有更简单的办法呢
sdc.cleardatabinding(this);//清掉绑定源
if(!string.IsNullOrEmpty(bstcode.Text))
strwhere+="a.stcode like '%"+bstcode.Text+"%' and ";
if(!string.IsNullOrEmpty(bstlea.Text))
strwhere+="a.stlec like '%"+bstlea.Text+"%' and ";
if(!string.IsNullOrEmpty(comboBox1.Text))
strwhere+="a.stlea like '"+comboBox1.SelectedValue.ToString()+"' and ";//以真实值做为查询条件
if(!string.IsNullOrEmpty(bstlec.Text))
strwhere+="a.stleb like '%"+bstlec.Text+"%' and ";
if(!string.IsNullOrEmpty(bre1.Text))
strwhere+="a.re1 like '%"+bre1.Text+"%' and ";
if(!string.IsNullOrEmpty(bdec1.Text))
strwhere+="a.stled like '%"+bdec1.Text+"%' and ";
if (strwhere.Length > 1)
{
strwhere = "select a.*,b.str2 as dddd from Epurchase a left join Evendor b on a.stlea = b.codestr where " + strwhere.Substring(0, strwhere.Length - 5) + ";" +
"select b.*,c.ccomunitname,convert(varchar(100),datea,23) as dateaa from Epurchase a left join Epurchaseson b on a.stcode=b.stcode left join Ainventory c on b.cinvcode = c.cinvcode where " + strwhere.Substring(0, strwhere.Length - 5);
dsaa = sdc.ads(strwhere);//生成datatable
我老是如上写查询语句,但当条件多的时候,就涉及更多,有没有更简单的办法呢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货