郑德才博客 记录学习,记录工作,学习知识分享!

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(); //查询方法
}
2012年4月10日 | 发布:郑德才博客 | 分类:学习之路 | 评论:0

发表留言: