[求助]组合查询的问题
要用有9个条件组合查询,我大概算了一下要用200多个if兄弟们帮我出出注意,看看怎么做才能省事省力啊
string sqlstr = "select * from table1 where 1=1";
if(条件1 != "")
{
sqlstr += " and 字段1='" + 条件1 + "'";
}
if(条件2 != "")
{
sqlstr += " and 字段2='" + 条件2 + "'";
}
if(条件3 != "")
{
sqlstr += " and 字段3='" + 条件3 + "'";
}
if(条件4 != "")
{
sqlstr += " and 字段4='" + 条件4 + "'";
}
if(条件5 != "")
{
sqlstr += " and 字段5='" + 条件5 + "'";
}
if(条件6 != "")
{
sqlstr += " and 字段6='" + 条件6 + "'";
}
if(条件7 != "")
{
sqlstr += " and 字段7='" + 条件7 + "'";
}
if(条件8 != "")
{
sqlstr += " and 字段8='" + 条件8 + "'";
}
if(条件9 != "")
{
sqlstr += " and 字段9='" + 条件9 + "'";
}
再执行sqlstr就行了.