Ejemplo n.º 1
0
        private DbCommand CreateCommand(CommandType commandType = CommandType.Text)
        {
            DbCommand dbcommand = DBFactory.CreateCommand();

            dbcommand.CommandType = commandType;
            return(dbcommand);
        }
Ejemplo n.º 2
0
        private DbCommand CreateCommand(string strSql, CommandType commandType = CommandType.Text)
        {
            DbCommand dbcommand = DBFactory.CreateCommand();

            dbcommand.CommandText = strSql;
            dbcommand.CommandType = commandType;
            return(dbcommand);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 执行无结果集的数据的操作命令
        /// </summary>
        /// <param name="ConnString">数据库连接字符串</param>
        /// <param name="Trans">Sql事务对象</param>
        /// <param name="CmdType">执行命令的类型</param>
        /// <param name="CmdText">存储过程或T-SQL语句等</param>
        /// <param name="CommandParameters">执行命令所需的参数数组</param>
        /// <returns>执行数据库操作所影响的行数</returns>
        public static int ExecuteNonQuery(string ConnString, IDbTransaction Trans, CommandType CmdType, string CmdText, params IDbDataParameter[] CommandParameters)
        {
            IDbCommand cmd = DBFactory.CreateCommand();

            using (IDbConnection conn = String.IsNullOrEmpty(ConnString) ? DBFactory.CreateConnection() : DBFactory.CreateConnection(ConnString, Config.DataBase.DbType.SQLSERVER)) {
                PrepareCommand(cmd, conn, Trans, CmdType, CmdText, CommandParameters);
                int val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                return(val);
            }
        }
Ejemplo n.º 4
0
        private DbCommand CreateCmd(string commandText = null, DbConnection DbConn = null)
        {
            DbCommand _DBCmd = DBFactory.CreateCommand();

            if (DbConn != null)
            {
                _DBCmd.Connection = DbConn;
            }
            if (!string.IsNullOrWhiteSpace(commandText))
            {
                _DBCmd.CommandText = commandText;
            }
            return(_DBCmd);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 执行有结果集的数据的操作指令
        /// </summary>
        /// <param name="ConnString">数据库连接字符串</param>
        /// <param name="Trans">Sql事务对象</param>
        /// <param name="CmdType">执行命令的类型</param>
        /// <param name="CmdText">存储过程或T-SQL语句等</param>
        /// <param name="CommandParameters">执行命令所需的参数数组</param>
        /// <returns>结果集</returns>
        public static IDataReader ExecuteReader(string ConnString, IDbTransaction Trans, CommandType CmdType, string CmdText, params IDbDataParameter[] CommandParameters)
        {
            IDbCommand    cmd  = DBFactory.CreateCommand();
            IDbConnection conn = String.IsNullOrEmpty(ConnString) ? DBFactory.CreateConnection() : DBFactory.CreateConnection(ConnString, Config.DataBase.DbType.SQLSERVER);

            try {
                PrepareCommand(cmd, conn, Trans, CmdType, CmdText, CommandParameters);
                cmd.CommandTimeout = 500;
                IDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Parameters.Clear();
                return(rdr);
            } catch (Exception ex) {
                conn.Close();
                throw new Exception(ex.ToString());
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 查询数据填充到数据集DataSet中
        /// </summary>
        /// <param name="ConnString">数据库连接字符串</param>
        /// <param name="Trans">Sql事务对象</param>
        /// <param name="CmdType">执行命令的类型</param>
        /// <param name="CmdText">存储过程或T-SQL语句等</param>
        /// <param name="CommandParameters">执行命令所需的参数数组</param>
        /// <returns>DataSet数据集</returns>
        public static DataSet ExecuteDataSet(string ConnString, IDbTransaction Trans, CommandType CmdType, string CmdText, params IDbDataParameter[] CommandParameters)
        {
            DataSet       ds   = new DataSet();
            IDbCommand    cmd  = DBFactory.CreateCommand();
            IDbConnection conn = String.IsNullOrEmpty(ConnString) ? DBFactory.CreateConnection() : DBFactory.CreateConnection(ConnString, Config.DataBase.DbType.SQLSERVER);

            try {
                PrepareCommand(cmd, conn, Trans, CmdType, CmdText, CommandParameters);
                IDataAdapter sda = DBFactory.CreateDataAdapter(cmd);
                sda.Fill(ds);
                return(ds);
            }
            catch (Exception ex) {
                throw new Exception(ex.ToString());
            }
            finally {
                conn.Close();
                cmd.Dispose();
            }
        }
Ejemplo n.º 7
0
        private DbCommand CreateCmd()
        {
            DbCommand _DBCmd = DBFactory.CreateCommand();

            return(_DBCmd);
        }