Beispiel #1
0
        public DataTable GetDataTable(string TargetTable, string orderField, string orderType)
        {
            StringBuilder sql = new StringBuilder();
            DataTable     result;

            try
            {
                sql.Append(string.Concat(new string[]
                {
                    "SELECT * FROM ",
                    TargetTable,
                    " ORDER BY ",
                    orderField,
                    " ",
                    orderType
                }));
                this.dbCommand = this.GetDatabase().GetSqlStringCommand(sql.ToString());
                result         = ReaderToIListHelper.DataTableToIDataReader(this.db.ExecuteReader(this.dbCommand));
            }
            catch (Exception e)
            {
                this.Logger.WriteLog(string.Concat(new string[]
                {
                    "-----------获取数据集DataTable-----------\r\n",
                    sql.ToString(),
                    "\r\n",
                    e.Message,
                    "\r\n"
                }));
                result = null;
            }
            return(result);
        }
Beispiel #2
0
        public DataTable GetDataTableProc(string procName, Hashtable ht)
        {
            DataTable result;

            try
            {
                this.dbCommand = this.GetDatabase().GetStoredProcCommand(procName);
                this.AddInParameter(this.dbCommand, ht);
                using (DbConnection conn = this.db.CreateConnection())
                {
                    conn.Open();
                    DbTransaction trans = conn.BeginTransaction();
                    result = ReaderToIListHelper.DataTableToIDataReader(this.db.ExecuteReader(this.dbCommand));
                }
            }
            catch (Exception e)
            {
                this.Logger.WriteLog(string.Concat(new string[]
                {
                    "-----------执行一存储过程DataTable-----------\r\n",
                    procName.ToString(),
                    "\r\n",
                    e.Message,
                    "\r\n"
                }));
                result = null;
            }
            return(result);
        }
Beispiel #3
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
     {
         dbCommand = this.GetDatabase().GetSqlStringCommand(sql.ToString());
         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);
     }
 }
        public DataTable GetDataTable(string TargetTable, string orderField, string orderType)
        {
            SQLiteConnection connection = new SQLiteConnection(connectionString);
            SQLiteCommand    cmd        = new SQLiteCommand("SELECT * FROM " + TargetTable + " order by " + orderField + orderType, connection);

            try
            {
                connection.Open();
                SQLiteDataReader myReader = cmd.ExecuteReader();
                return(ReaderToIListHelper.DataTableToIDataReader(myReader));
            }
            catch (System.Data.SQLite.SQLiteException e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 获取数据表,没有条件
        /// </summary>
        /// <param name="TargetTable">目标表名</param>
        /// <returns>DataTable</returns>
        public DataTable GetDataTable(string TargetTable)
        {
            StringBuilder sql = new StringBuilder();

            try
            {
                sql.Append("SELECT * FROM " + TargetTable + "");
                dbCommand = this.GetDatabase().GetSqlStringCommand(sql.ToString());
                return(ReaderToIListHelper.DataTableToIDataReader(db.ExecuteReader(dbCommand)));
            }
            catch (Exception e)
            {
                Logger.Error("-----------获取数据集DataTable-----------\r\n" + sql.ToString() + "\r\n" + e + "\r\n");
                return(null);
            }
        }
        public DataTable GetDataTableBySQL(StringBuilder sql, SqlParam[] param)
        {
            SQLiteConnection connection = new SQLiteConnection(connectionString);
            SQLiteCommand    cmd        = new SQLiteCommand();

            try
            {
                PrepareCommand(cmd, connection, null, sql.ToString(), param);
                SQLiteDataReader myReader = cmd.ExecuteReader();
                cmd.Parameters.Clear();
                return(ReaderToIListHelper.DataTableToIDataReader(myReader));
            }
            catch (System.Data.SQLite.SQLiteException e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #8
0
 /// <summary>
 /// 摘要:
 ///     执行一存储过程DataTable
 /// 参数:
 ///     procName:存储过程名称
 ///     Hashtable:传入参数字段名
 /// </summary>
 public DataTable GetDataTableProc(string procName, Hashtable ht)
 {
     try
     {
         dbCommand = this.GetDatabase().GetStoredProcCommand(procName);
         this.AddInParameter(dbCommand, ht);
         using (DbConnection conn = db.CreateConnection())
         {
             conn.Open();
             DbTransaction trans = conn.BeginTransaction();
             return(ReaderToIListHelper.DataTableToIDataReader(db.ExecuteReader(dbCommand)));
         }
     }
     catch (Exception e)
     {
         Logger.WriteLog("-----------执行一存储过程DataTable-----------\r\n" + procName.ToString() + "\r\n" + e.Message + "\r\n");
         return(null);
     }
 }
Beispiel #9
0
        public DataTable GetDataTableBySQL(StringBuilder sql, SqlParam[] param)
        {
            DataTable result;

            try
            {
                this.dbCommand = this.GetDatabase().GetSqlStringCommand(sql.ToString());
                this.AddInParameter(this.dbCommand, param);
                result = ReaderToIListHelper.DataTableToIDataReader(this.db.ExecuteReader(this.dbCommand));
            }
            catch (Exception e)
            {
                this.Logger.WriteLog(string.Concat(new string[]
                {
                    "-----------获取数据集DataTable-----------\r\n",
                    sql.ToString(),
                    "\r\n",
                    e.Message,
                    "\r\n"
                }));
                result = null;
            }
            return(result);
        }