日期:2014-05-17 浏览次数:20471 次
protected void Button1_Click(object sender, EventArgs e) { string strSQL = "Select lid lname lpass ltouxiang lxingbie From Test Where " + getCondition; //DataTable dt = getQuery(strSQL);执行查询语句。 } private string getCondition() { //初始化数组 string[] cCons = "lid=@lid,lname=@lname,lpass=@lpass,ltouxiang=@ltouxiang,lxingbie=@lxingbie".Split(','); string cCondition = "(1=0 "; for (int iC0 = 0; iC0 < cCons.Length; iC0++) { for (int iC1 = 0; iC1 < cCons.Length; iC1++) { if (iC1 == iC0) continue; for (int iC2 = 0; iC2 < cCons.Length; iC2++) { if (iC2 == iC0 || iC2 == iC1) continue; cCondition += "\n OR ( " + cCons[iC0] + " And " + cCons[iC1]+ " And " + cCons[iC2]+ ")"; } } } cCondition += "\n)"; return cCondition; }
------解决方案--------------------
上面打错了,又不给改,该死的网站。
代码重新贴:
protected void ExecMyQuery(string lid,string lname,string lpass ,string ltouxiang ,string lxingbie ) { string strSQL = @"Declare @lid nvarchar(300), @lname nvarchar(300), @lpass nvarchar(300), @ltouxiang nvarchar(300), @lxingbie nvarchar(300)"; strSQL += "Select @lid='" + txtLid + "',@lname='" + lname + "',@lpass='" + lpass + "',@ltouxiang='" + ltouxiang + "',@lxingbie='" + lxingbie + "'"; strSQL += "Select lid lname lpass ltouxiang lxingbie From Test Where " + getCondition(); //DataTable dt = getQuery(strSQL); } private string getCondition() { //初始化数组 string[] cCons = "lid=@lid,lname=@lname,lpass=@lpass,ltouxiang=@ltouxiang,lxingbie=@lxingbie".Split(','); string cCondition = "(1=0 "; for (int iC0 = 0; iC0 < cCons.Length; iC0++) { for (int iC1 = 0; iC1 < cCons.Length; iC1++) { if (iC1 == iC0) continue; for (int iC2 = 0; iC2 < cCons.Length; iC2++) { if (iC2 == iC0 || iC2 == iC1) continue; cCondition += "\n OR ( " + cCons[iC0] + " And " + cCons[iC1]+ " And " + cCons[iC2]+ ")"; } } } cCondition += "\n)"; return cCondition; }
------解决方案--------------------