Exemple #1
0
        /// <summary>
        /// 按条件查询获取实体信息
        /// </summary>
        /// <param name="strWhere"></param>
        /// <param name="strCols"></param>
        /// <param name="paras"></param>
        /// <returns></returns>
        public T GetModel(string strWhere, string strCols, params SqlParameter[] paras)
        {
            //生成查询语句
            string selSql = CreateSql.CreateSelectSql <T>(strWhere, strCols);
            //生成Reader对象
            SqlDataReader reader = SqlHelper.ExecuteReader(selSql, 1, paras);
            //转换为实体对象
            T model = DbConvert.SqlDataReaderToModel <T>(reader, strCols);

            //关闭阅读器
            reader.Close();
            return(model);
        }
Exemple #2
0
        /// <summary>
        /// 按条件查询返回实体列表
        /// </summary>
        /// <param name="strWhere">条件</param>
        /// <param name="strCols">查询字段</param>
        /// <param name="paras">参数数组</param>
        /// <returns>List<T></returns>
        public List <T> GetModelList(string strWhere, string strCols, params SqlParameter[] paras)
        {
            if (string.IsNullOrEmpty(strWhere))
            {
                strWhere = "1=1";
            }
            //生成查询语句
            string selSql = CreateSql.CreateSelectSql <T>(strWhere, strCols);
            //生成Reader
            SqlDataReader reader = SqlHelper.ExecuteReader(selSql, 1, paras);
            //转换为List<T>列表
            List <T> list = DbConvert.SqlDataReaderToList <T>(reader, strCols);

            //关闭阅读器
            reader.Close();
            return(list);
        }