Microsoft Visual Studio在多条件查询数据库时,应该怎么拼接?(模糊查询和精确查询)

2025-05-20 22:49:31
推荐回答(1个)
回答1:

string name; //名字
int sex; //年龄
string sql="select * from a where 1=1"; //语句

if(name!=null){
sql+=" and name='"+name+"'";

}
if(int sex>0){
sql+=" and sex="+sex;

}