Exemplo n.º 1
0
        /// <summary>
        /// 获取DataSet
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public DataSet GetDataSetAll(string sql, params SqlParameter[] pars)
        {
            ExecLogEvent(sql, pars, true);
            SqlDataAdapter _sqlDataAdapter = new SqlDataAdapter(sql, _sqlConnection);

            if (_tran != null)
            {
                _sqlDataAdapter.SelectCommand.Transaction = _tran;
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(_sqlDataAdapter.SelectCommand.Parameters);
            }
            _sqlDataAdapter.SelectCommand.CommandTimeout = this.CommandTimeOut;
            _sqlDataAdapter.SelectCommand.CommandType    = CommandType;
            _sqlDataAdapter.SelectCommand.Parameters.AddRange(pars);
            DataSet ds = new DataSet();

            _sqlDataAdapter.Fill(ds);
            if (IsClearParameters)
            {
                _sqlDataAdapter.SelectCommand.Parameters.Clear();
            }
            ExecLogEvent(sql, pars, false);
            return(ds);
        }
Exemplo n.º 2
0
        public SqlDataReader GetReader(string sql, params SqlParameter[] pars)
        {
            SqlCommand sqlCommand = new SqlCommand(sql, _sqlConnection);

            sqlCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                sqlCommand.Transaction = _tran;
            }
            if (pars != null)
            {
                sqlCommand.Parameters.AddRange(pars);
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(sqlCommand.Parameters);
            }
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

            if (isClearParameters)
            {
                sqlCommand.Parameters.Clear();
            }
            return(sqlDataReader);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 执行SQL返回受影响行数
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public int ExecuteCommand(string sql, params SqlParameter[] pars)
        {
            ExecLogEvent(sql, pars, true);
            SqlCommand sqlCommand = new SqlCommand(sql, _sqlConnection);

            sqlCommand.CommandType    = CommandType;
            sqlCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                sqlCommand.Transaction = _tran;
            }
            if (pars != null)
            {
                sqlCommand.Parameters.AddRange(pars);
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(sqlCommand.Parameters);
            }
            int count = sqlCommand.ExecuteNonQuery();

            if (IsClearParameters)
            {
                sqlCommand.Parameters.Clear();
            }
            ExecLogEvent(sql, pars, false);
            return(count);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取第一行第一列
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public object GetScalar(string sql, params SqlParameter[] pars)
        {
            ExecLogEvent(sql, pars, true);
            SqlCommand sqlCommand = new SqlCommand(sql, _sqlConnection);

            sqlCommand.CommandType = CommandType;
            if (_tran != null)
            {
                sqlCommand.Transaction = _tran;
            }
            sqlCommand.CommandTimeout = this.CommandTimeOut;
            if (pars != null)
            {
                sqlCommand.Parameters.AddRange(pars);
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(sqlCommand.Parameters);
            }
            object scalar = sqlCommand.ExecuteScalar();

            scalar = (scalar == null ? 0 : scalar);
            if (IsClearParameters)
            {
                sqlCommand.Parameters.Clear();
            }
            ExecLogEvent(sql, pars, false);
            return(scalar);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取DataReader
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public virtual SqlDataReader GetReader(string sql, params SqlParameter[] pars)
        {
            ExecLogEvent(sql, pars, true);
            SqlCommand sqlCommand = new SqlCommand(sql, _sqlConnection);

            sqlCommand.CommandType    = this.CommandType;
            sqlCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                sqlCommand.Transaction = _tran;
            }
            if (pars != null)
            {
                sqlCommand.Parameters.AddRange(pars);
            }
            if (this.IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(sqlCommand.Parameters);
            }
            CheckConnect();
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

            if (this.IsClearParameters)
            {
                sqlCommand.Parameters.Clear();
            }
            ExecLogEvent(sql, pars, false);
            return(sqlDataReader);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取DataTable
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public virtual DataTable GetDataTable(string sql, params SqlParameter[] pars)
        {
            SetCurrentConnection(false);
            ExecLogEvent(sql, pars, true);
            SqlDataAdapter _sqlDataAdapter = new SqlDataAdapter(sql, _sqlConnection);

            _sqlDataAdapter.SelectCommand.CommandType = this.CommandType;
            if (pars != null)
            {
                _sqlDataAdapter.SelectCommand.Parameters.AddRange(pars);
            }
            if (this.IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(_sqlDataAdapter.SelectCommand.Parameters);
            }
            _sqlDataAdapter.SelectCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                _sqlDataAdapter.SelectCommand.Transaction = _tran;
            }
            CheckConnect();
            DataTable dt = new DataTable();

            _sqlDataAdapter.Fill(dt);
            if (this.IsClearParameters)
            {
                _sqlDataAdapter.SelectCommand.Parameters.Clear();
            }
            ExecLogEvent(sql, pars, false);
            return(dt);
        }
Exemplo n.º 7
0
        public DataTable GetDataTable(string sql, params SqlParameter[] pars)
        {
            SqlDataAdapter _sqlDataAdapter = new SqlDataAdapter(sql, _sqlConnection);

            _sqlDataAdapter.SelectCommand.Parameters.AddRange(pars);
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(_sqlDataAdapter.SelectCommand.Parameters);
            }
            _sqlDataAdapter.SelectCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                _sqlDataAdapter.SelectCommand.Transaction = _tran;
            }
            DataTable dt = new DataTable();

            _sqlDataAdapter.Fill(dt);
            _sqlDataAdapter.SelectCommand.Parameters.Clear();
            return(dt);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 创建一个新的SQL连接
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public virtual SqlCommand CreateSqlCommand(string sql, params SqlParameter[] pars)
        {
            SqlCommand sqlCommand = new SqlCommand(sql, _sqlConnection);

            sqlCommand.CommandType    = this.CommandType;
            sqlCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                sqlCommand.Transaction = _tran;
            }
            if (pars != null)
            {
                sqlCommand.Parameters.AddRange(pars);
            }
            if (this.IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(sqlCommand.Parameters);
            }

            return(sqlCommand);
        }