读书人

.数据库有关问题 LIKE 语句.

发布时间: 2013-08-06 16:47:25 作者: rapoo

.................数据库问题 LIKE 语句...................
多条件查询 其中一个like 其他精确查询 select * from indent where indentnum = '" + i.Indentnum + "' or date ='" + i.Dyevatnum + "'or dyevatnum='"+i.dyevat+"'"

只有date有值的时候多条件查询才成功 date空着查询就不行了 显示全表了
[解决办法]

string sql="select * from indent where 1=1";
if(!string.IsNullOrEmpty( i.Indentnum ))
{
sql+= " AND indentnum ='"+ i.Indentnum + "';
}
//...

读书人网 >C#

热点推荐