按条件部分查询

///

/// 取得部分广告记录(按条件查询) /// /// /// public DataTable GetPartAdvertisement(IDictionary hash) { StringBuilder sbSql = new StringBuilder(); sbSql.Append("select ID,Name,LinkUrl,LogoPath,Type,Description,AdminID,SendTime,IsDelete from tbAdvertisement"); sbSql.Append(" where IsDelete = 1"); List listParms = new List(); if (hash.Count > 0) { foreach (DictionaryEntry de in hash) { switch (de.Key.ToString()) { case "Name": sbSql.Append(" and Name like @Name"); listParms.Add(CommonHelp.MakeInParam("@Name", (DbType)SqlDbType.NVarChar, 50, "%" + de.Value + "%")); break; case "DateStart": if (de.Value.ToString() != "") { sbSql.Append(" and SendTime > @DateStart"); listParms.Add(CommonHelp.MakeInParam("@DateStart", (DbType)SqlDbType.DateTime, 8, de.Value)); } break; case "DateEnd": if (de.Value.ToString() != "") { sbSql.Append(" and SendTime < @DateEnd"); listParms.Add(CommonHelp.MakeInParam("@DateEnd", (DbType)SqlDbType.DateTime, 8, de.Value)); } break; case "Type": if (de.Value.ToString() != "0") { sbSql.Append(" and Type = @Type"); listParms.Add(CommonHelp.MakeInParam("@Type", (DbType)SqlDbType.Int, 4, de.Value)); } break; default: break; } } } sbSql.Append(" order by SendTime desc"); DataSet ds = DbHelp.ExecuteDataSet(CommandType.Text, sbSql.ToString(), listParms); return ds.Tables[0]; }

你可能感兴趣的:(C#)