SQL query operation

There are seven conditions of any of the filter conditions can be screened. LINQ query using more complicated, and increases the operation steps, with the selection determination SQL.

 public DataTable GetData(string cboCld, string cboFact,string cboPrtN,string  txtbCde,string txtbDce,string txtbPdt,string txtbRID)
        {
            string strSql = @"select distinct l.Area,l.Facility ,m.vdpartno,l.PartNo,l.ReelID,l.Qty ,l.Location,l.datecd,l.prodcd,l.vendorcd,l.lmdate from VMIReelShelfDetail l 
left JOIN smtitem  m
ON m.partno  = l.partno 
where l.ReelID <>''";
            if (cboCld != "ALL")
            {
                strSql = strSql + " AND  l.Area='" + cboCld + "'";
            }
            if (cboFact != "ALL")
            {
                strSql = strSql + " AND  l.Facility='" + cboFact + "'";
            }
            if (cboPrtN != "ALL")
            {
                strSql = strSql + " AND  l.PartNo='" + cboPrtN + "'";
            }
            if (txtbCde != "")
            {
                strSql = strSql + " AND  l.vendorcd='" + txtbCde + "'";
            }
            if (txtbDce != "")
            {
                strSql = strSql + " AND  l.datecd='" + txtbDce + "'";
            }
            if (txtbPdt != "")
            {
                strSql = strSql + " AND  l.prodcd='" + txtbPdt + "'";
            }
            if (txtbRID != "")
            {
                strSql = strSql + " AND  l.ReelID='" + txtbRID + "'";
            }
            return SqlHelper.Query(strSql);
        }

 

By judgment text boxes and check boxes on these screens to append SQL query in the most convenient and simple.

Guess you like

Origin www.cnblogs.com/cdjbolg/p/11771783.html