asp.net 多条件查询
string sql = "select * from [product] where 1=1";
//商品名称不为空
if (shopName != "")
{
sql += " and [proName]='" + shopName + "'";
}
//商品编号不为空
if (Number != "")
{
sql += " and [proOwnerId]='" + Number + "'";
}
//商品说明不为空
if (shopRemark != "")
{
sql += " and [promiaoshu]=" + shopRemark + "'";
}
//一级类别不为空
if (dropClass != "")
{
sql += " and [proclass]='" + dropClass + "'";
}
//二级类别不为空
if (dropclass1 != "")
{
sql += " and [class]='" + dropclass1 + "'";
}
//三级类别不为空
if (dropclass2 != "")
{
sql += " or [ThreeClass]='" + dropclass2 + "'";
}
//商品名称不为空
if (shopName != "")
{
sql += " and [proName]='" + shopName + "'";
}
//商品编号不为空
if (Number != "")
{
sql += " and [proOwnerId]='" + Number + "'";
}
//商品说明不为空
if (shopRemark != "")
{
sql += " and [promiaoshu]=" + shopRemark + "'";
}
//一级类别不为空
if (dropClass != "")
{
sql += " and [proclass]='" + dropClass + "'";
}
//二级类别不为空
if (dropclass1 != "")
{
sql += " and [class]='" + dropclass1 + "'";
}
//三级类别不为空
if (dropclass2 != "")
{
sql += " or [ThreeClass]='" + dropclass2 + "'";
}