经常遇到条件查询是多个条件一起查询,这样可以比较方便的把条件语句拼接在一起

    sqlStr += " where 1=1 ";
    if(name!= "不选择")
    {
         sqlStr += " and name= '" + name+ "'";
    }
    else if(r1!= "不选择")
    {
        sqlStr += " and r1= '" + r1+ "'";
    }
    else if(dataType != "不选择")
    {
        sqlStr += " and DataType = '" + dataType + "'";
    }
    else if(fileType != "不选择")
    {
        sqlStr += " and FileType = '" + fileType + "'";
    }

更多推荐

sql语句多条件查询语句拼接