10
2012
04

asp.net 多重条件查询语句

按钮查询数据:
protected void ImageSelect_Click(object sender, ImageClickEventArgs e)
{
where.Text = "";
string contion = " where 1=1 ";//使用一个真条件,后面跟上搜索的条件,条件是否为空,都可以执行

if (Text1.Text.Trim() != "")
{
contion = contion + "and Text1 like '%" + Text1.Text.Trim() + "%'";
}
if (Text2.Text.Trim() != "")
{
contion = contion + "and Text2 like '%" + Text2.Text.Trim() + "%'";
}
if (Text3.Text.Trim() != "")
{
contion = contion + "and Text3 like '%" + Text3 .Text.Trim() + "%'";
}
if (DropDownList1.SelectedValue != "")
{
contion = contion + "and DropDownList1like '" + DropDownList1.SelectedValue + "%'";
}
where.Text = contion;

select(); //查询方法
}
« 上一篇下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。