首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ASP.NET怎么实现多条件的查询语句

2011-12-24 
ASP.NET如何实现多条件的查询语句如何实现多条件的查询语句stringstr select*frompub if(text1.Text!

ASP.NET如何实现多条件的查询语句
如何实现多条件的查询语句
string   str   = "select   *   from   pub ";
if(text1.Text   != " ")
    str   += "   where   id= ' "   +   this.text1.Text   +   " ' ";
if(text2.Text   != " ")
    str   += " '     and   name= ' "   +   this.text2.Text   +   " ' ";
if(text3.Text   != " ")
    str   += " '     and   condition   = ' "   +   this.text3.Text   +   " ' ";
.
.
.
如何实现呢?

[解决办法]
string str = "select * from pub "; 改为:string str = "select * from pub where 1=1 ";然后下面全部用and conditon就可以了
[解决办法]
1)string str = "select * from pub "; 改为:string str = "select * from pub where 1=1 ";然后下面全部用and conditon就可以了
2)
如何实现多条件的查询语句
str = " ";
if(text1.Text != " ")

str += " where id= ' " + this.text1.Text + " ' ";
if(text2.Text != " ")
str += " ' and name= ' " + this.text2.Text + " ' ";
if(text3.Text != " ")
str += " ' and condition = ' " + this.text3.Text + " ' ";
[解决办法]
str = " ";
if(text1.Text != " ")
{
if (str!= " ") str+= " and "
str += " id= ' " + this.text1.Text + " ' ";
}
if(text2.Text != " ")
{
if (str!= " ") str+= " and "

str += " ' and name= ' " + this.text2.Text + " ' ";
if(text3.Text != " ")
str += " ' and condition = ' " + this.text3.Text + " ' ";

热点排行