if(ad!=null|ad!=''){
string str="select * from A where A_id=4 and a_name="+ad}else{
select * from A where A_id=4
}
要是where后面有在多的参数 ,x,y,z就得写更多的if因为要判断他们是否为空,
有什么解决办法吗
string str="select * from A where A_id=4 and a_name="+ad}else{
select * from A where A_id=4
}
要是where后面有在多的参数 ,x,y,z就得写更多的if因为要判断他们是否为空,
有什么解决办法吗
if(...)
str += ...
if(!string.IsNullOrEmpty(x)) {
strSql += " and x="+ x ;
}if(!string.IsNullOrEmpty(y)) {
strSql += " and y="+ y ;
}
如果不想这么麻烦,可以定义一个实体,通过反射机制来做!