/// <summary> /// 获取数据列表 带参数化 /// </summary> /// <typeparam name="T">实体</typeparam> /// <param name="commandText">SQL语句</param> /// <param name="countTable">分页获取总数的表名及条件</param> /// <returns></returns> public List <T> GetList <T>(string commandText, UtilityPager utilityPager = null, string countTable = null, SqlParameter[] parmarr = null) where T : BaseTO, new() { MSSQLSqlHelper db = new MSSQLSqlHelper(connectionkey); List <T> list = new List <T>(); //是否需要分页 if (utilityPager != null) { string sqlcount = string.Format("select count(*) from {0}", countTable); utilityPager.Count = int.Parse(db.ExecuteScalar(sqlcount, CommandType.Text, parmarr).ToString()); commandText = PagingAll(commandText, utilityPager.PageIndex, utilityPager.PageSize); } using (SqlDataReader reader = db.ExecuteReader(commandText, CommandType.Text, parmarr)) { if (reader.HasRows) { while (reader.Read()) { T to = new T(); to.Initialize(reader); list.Add(to); } } } return(list); }
/// <summary> /// 返回结果中第一行第一列结果 /// </summary> /// <param name="commandText">SQL语句</param> /// <returns></returns> public object GetUniqueResult(string commandText) { MSSQLSqlHelper db = new MSSQLSqlHelper(connectionkey); return(db.ExecuteScalar(commandText)); }