StringBuilder sql=new StringBuilder("select * from T ");
List<string> wheres=new List<string>();
if(adsf!=0)
{
wheres.Add(" pId="+a);
}
if(...)
{wheres.Add(" pName="+b);}
//判断用户是否选择了条件
if(wheres.Count > 0)
{
string wh=string.Join(" and",wheres.ToArray());
sql.Append(" where "+wh);
}