读书人

初级有关问题,请各位帮忙

发布时间: 2012-03-20 14:01:11 作者: rapoo

初级问题,请各位帮忙
类似搜索页面,因为判断条件多,求一个简单些的方法,我写的好烦琐,下面就是我写的,还只是一部分的判断呢,请帮忙

if (topCount1 == " " || topCount1 == null)
{
if (other1 == "1 ")
{
DB1 db1 = new DB1();
string Sql = "select * from ProductBaseInfo ";
db1.SetDataBinding(dg, Sql);
db1.CloseDataBase();
}
if (other1 == "2 ")
{
DB1 db1 = new DB1();
string Sql = "select * from ProductBaseInfo ";
db1.SetDataBinding(dg, Sql);
db1.CloseDataBase();
}
if (other1 == "3 ")
{
DB1 db1 = new DB1();
string Sql = "select * from
db1.SetDataBinding(dg, Sql);
db1.CloseDataBase();
}
if (other1 == " " || other1 == null)
{
DB1 db1 = new DB1();
string Sql = "select * from ProductBaseInfo


db1.SetDataBinding(dg, Sql);
db1.CloseDataBase();
}
}

[解决办法]
switch (other1)
{
case "1 ":
....
break;
case "2 ":
....
break;
default:
break;
}
[解决办法]
如上,我感觉简练些好

string Sql ;
switch(other1)
{
case "1 ":
Sql = "select * from ProductBaseInfo ";
break;
case "2 ":
Sql = "select * from ProductBaseInfo ";
break;
}
[解决办法]
那就再没个case后面给Sql变量加where条件,
操作数据库不用每个if里都写吧- -#
string Sql= "select * from ProductBaseInfo " ;
switch(other)
{
case "1 ":
Sql += "where... ";
break;
case "2 ":
Sql += "where... "; ";
break;
}

读书人网 >asp.net

热点推荐