判断多个参数是否为空 如果不为空则作为条件合成sql语句.
下面是c#写的方法,不知还有没有更好的实现方法。欢迎留言指正。
public string findstrbm(string dlzh, string xm, string zw, string bm) { string strwhere = ""; dlzh = dlzh.Trim(); xm = xm.Trim(); zw = zw.Trim(); bm = bm.Trim(); if (dlzh == "" && zw == "" && xm == "" && bm == "") { return ""; } if (dlzh != "") { strwhere = " dlzh='" + dlzh + "'and"; } if (xm!="") { strwhere+=" xm='"+xm+"'and"; } if (zw!="") { strwhere+=" zw='"+zw+"'and"; } if (bm != "") { strwhere += " bm='" + bm + "'and"; } strwhere = strwhere.Substring(0, strwhere.Length - 3); return " where " + strwhere; }