sql多条件查询语句

来源:互联网 发布:小楼昨夜又东风 知乎 编辑:程序博客网 时间:2024/04/29 13:46

如上图:三个文本可选项,那sql语句怎么写呢?

1、首先获取三个文本的值分别为Name,Age,Sex.

2、string sql="select * from 表 where 1=1";

3、if(Name!="")

{

sql=sql+"and userName like '%" + Name + "%'";

}

if(Age!="")

{

sql=sql+"and Age like '%" + Age + "%'";

}

if(Sex!="")

{

sql=sql+"and Sex like '%" +Sex + "%'";

}

 

 

 

 

原创粉丝点击