多條件模糊查詢
阿新 • • 發佈:2019-02-08
#region 多條件搜尋時,使用List集合來拼接條件(拼接Sql) //StringBuilder sql = new StringBuilder("select * from PhoneNum"); List<string> wheres = new List<string>(); if (!string.IsNullOrEmpty(strRWMC)) { wheres.Add(" F_TASKNAME like '%" + strRWMC + "%'"); } if (!string.IsNullOrEmpty(strSCDW)) { wheres.Add(" F_PRODUCTIONUNIT like '%" + strSCDW + "%'"); } if (!string.IsNullOrEmpty(strRWZT)) { wheres.Add(" F_TASKSTATE like '%" + strRWZT + "%'"); } //判斷使用者是否選擇了條件 string wh = null; if (wheres.Count > 0) { wh = string.Join(" and ", wheres.ToArray()); //sql.Append(" where " + wh); } pQueryFilter = new QueryFilter(); pQueryFilter.WhereClause = wh; refreshForm(pQueryFilter); #endregion