Esempio n. 1
0
        /// <summary>
        /// 以事务的方式执行相应的命令,返回结果集中的第一行第一列的值,如果不成功则返回null值
        /// </summary>
        /// <param name="cmd">需要执行的DbCommand命令对象</param>
        /// <param name="trans">数据库事务对象</param>
        /// <returns>返回结果集中的第一行第一列的值,如果不成功则返回null值</returns>
        public object ExecuteScalar(DbCommand cmd, Trans trans)
        {
            if (cmd != null)
            {
                cmd.Connection.Close();

                cmd.Connection = trans.Connection;
                cmd.Transaction = trans.Transaction;

                object retVal = cmd.ExecuteScalar();

                return retVal;
            }

            return null;
        }
Esempio n. 2
0
        /// <summary>
        /// 以事务的方式执行相应的命令,返回一个DbDataReader数据对象,如果没有则返回null值
        /// </summary>
        /// <param name="cmd">需要执行DbCommand命令对象</param>
        /// <param name="trans">数据库事务对象</param>
        /// <returns>返回一个DbDataReader数据对象,如果没有则返回null值</returns>
        public DbDataReader ExecuteReader(DbCommand cmd, Trans trans)
        {
            if (cmd != null)
            {
                cmd.Connection.Close();

                cmd.Connection = trans.Connection;
                cmd.Transaction = trans.Transaction;

                DbDataReader reader = cmd.ExecuteReader();

                return reader;
            }

            return null;
        }
Esempio n. 3
0
        /// <summary>
        /// 以事务的方式执行相应的命令,返回一个DataTable数据集合
        /// </summary>
        /// <param name="cmd"> 需要执行的DbCommand命令对象</param>
        /// <param name="trans">数据库事务对象</param>
        /// <returns>返回一个DataTable数据集合</returns>
        public DataTable ExecuteDataTable(DbCommand cmd, Trans trans)
        {
            DataTable dataTable = new DataTable();

            if (cmd != null)
            {
                cmd.Connection = trans.Connection;
                cmd.Transaction = trans.Transaction;

                DbDataAdapter dbDataAdapter = this._dbFactory.CreateDataAdapter();
                dbDataAdapter.SelectCommand = cmd;

                dbDataAdapter.Fill(dataTable);
            }

            return dataTable;
        }
Esempio n. 4
0
        /// <summary>
        /// 以事务的方式执行相应的命令,返回影响的数据记录数,如果不成功则返回-1
        /// </summary>
        /// <param name="cmd">需要执行的DbCommand命令对象</param>
        /// <param name="trans">数据库事务对象</param>
        /// <returns>返回影响的数据记录数,如果不成功则返回-1</returns>
        public int ExecuteNonQuery(DbCommand cmd, Trans trans)
        {
            if (cmd != null)
            {
                cmd.Connection.Close();

                cmd.Connection = trans.Connection;
                cmd.Transaction = trans.Transaction;

                int retVal = cmd.ExecuteNonQuery();

                return retVal;
            }

            return -1;
        }
Esempio n. 5
0
        /// <summary>
        /// 已事务的方式执行相应的命令,返回一个DataSet数据集合
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="trans"></param>
        /// <returns></returns>
        public DataSet ExecuteDataSet(DbCommand cmd, Trans trans)
        {
            DataSet ds = new DataSet();

            if(cmd != null)
            {
                cmd.Connection = trans.Connection;
                cmd.Transaction = trans.Transaction;

                DbDataAdapter dbDataAdapter = this._dbFactory.CreateDataAdapter();
                dbDataAdapter.SelectCommand = cmd;

                dbDataAdapter.Fill(ds);
            }

            return ds;
        }