예제 #1
0
        /// <summary>
        /// 根据 SQL 返回 IList,带参数 (比DataSet效率高)
        /// </summary>
        /// <typeparam name="T">实体类</typeparam>
        /// <param name="sql">Sql语句</param>
        /// <param name="param">参数化</param>
        /// <returns></returns>
        public IList GetDataListBySQL <T>(StringBuilder sql, SqlParam[] param)
        {
            IList list = new List <T>();

            dbCommand = this.GetDatabase().GetSqlStringCommand(sql.ToString());
            this.AddInParameter(dbCommand, param);
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                list = ReaderToIListHelper.ReaderToList <T>(dataReader);
            }
            return(list);
        }
예제 #2
0
 /// <summary>
 /// 摘要:
 ///     执行一存储过程DataTable
 /// 参数:
 ///     procName:存储过程名称
 ///     Hashtable:传入参数字段名
 /// </summary>
 public DataTable GetDataTableProc(string procName, Hashtable ht)
 {
     try
     {
         dbCommand = this.GetDatabase().GetStoredProcCommand(procName);
         this.AddInParameter(dbCommand, ht);
         return(ReaderToIListHelper.DataTableToIDataReader(db.ExecuteReader(dbCommand)));
     }
     catch (Exception e)
     {
         Logger.WriteLog("-----------执行一存储过程DataTable-----------\r\n" + procName.ToString() + "\r\n" + e.Message + "\r\n");
         return(null);
     }
 }
예제 #3
0
        /// <summary>
        /// 获取数据表,排序
        /// </summary>
        /// <param name="TargetTable">目标表名</param>
        /// <param name="orderField">排序字段</param>
        /// <param name="orderType">排序类型</param>
        /// <returns></returns>
        public DataTable GetDataTable(string TargetTable, string orderField, string orderType)
        {
            StringBuilder sql = new StringBuilder();

            try
            {
                sql.Append("SELECT * FROM " + TargetTable + " ORDER BY " + orderField + " " + orderType + "");
                dbCommand = this.GetDatabase().GetSqlStringCommand(sql.ToString());
                return(ReaderToIListHelper.DataTableToIDataReader(db.ExecuteReader(dbCommand)));
            }
            catch (Exception e)
            {
                Logger.WriteLog("-----------获取数据集DataTable-----------\r\n" + sql.ToString() + "\r\n" + e.Message + "\r\n");
                return(null);
            }
        }
예제 #4
0
 /// <summary>
 /// 根据 SQL 返回 DataTable 数据集,带参数
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="param">参数化</param>
 /// <returns>DataTable</returns>
 public DataTable GetDataTableBySQL(StringBuilder sql, SqlParam[] param)
 {
     try
     {
         //  Logger.WriteLog("GetDataTableBySQL");
         dbCommand = this.GetDatabase().GetSqlStringCommand(sql.ToString());
         // Logger.WriteLog("GetDataTableBySQL dbCommand");
         this.AddInParameter(dbCommand, param);
         return(ReaderToIListHelper.DataTableToIDataReader(db.ExecuteReader(dbCommand)));
     }
     catch (Exception e)
     {
         Logger.WriteLog("-----------获取数据集DataTable-----------\r\n" + sql.ToString() + "\r\n" + e.Message + "\r\n");
         return(null);
     }
 }
예제 #5
0
        /// <summary>
        /// 获取数据表,没有条件
        /// </summary>
        /// <param name="TargetTable">目标表名</param>
        /// <returns>DataTable</returns>
        public DataTable GetDataTable(bool isAll, string TargetTable)
        {
            StringBuilder sql = new StringBuilder();

            try
            {
                if (!isAll)
                {
                    sql.Append(TargetTable);
                }
                else
                {
                    sql.Append("SELECT * FROM " + TargetTable + "");
                }
                dbCommand = this.GetDatabase().GetSqlStringCommand(sql.ToString());
                return(ReaderToIListHelper.DataTableToIDataReader(db.ExecuteReader(dbCommand)));
            }
            catch (Exception e)
            {
                Logger.WriteLog("-----------获取数据集DataTable-----------\r\n" + sql.ToString() + "\r\n" + e.Message + "\r\n");
                return(null);
            }
        }