Exemple #1
0
 /// <summary>
 /// 执行存储过程,返回comd对象
 /// </summary>
 /// <param name="spName">存储过程名</param>
 /// <param name="pars">参数集</param>
 /// <returns></returns>
 private SqlCommand CreateComd(string spName, DbParameters pars)
 {
     try
     {
         SqlCommand comd = CreateComd(spName);
         int        len  = pars.Len;
         if (len > 0)
         {
             for (int i = 0; i < len; i++)
             {
                 comd.Parameters.Add(pars[i]);
             }
         }
         return(comd);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemple #2
0
 /// <summary>
 /// 执行SQL语句,返回SqlDataAdapter对象
 /// </summary>
 /// <param name="sqlStr">SQL语句</param>
 /// <param name="pars">参数集</param>
 /// <returns></returns>
 public SqlDataAdapter CreateSqlAdapter(string sqlStr, DbParameters pars)
 {
     try
     {
         SqlDataAdapter comdAdapter = CreateSqlAdapter(sqlStr);
         int            len         = pars.Len;
         if (len > 0)
         {
             for (int i = 0; i < len; i++)
             {
                 comdAdapter.SelectCommand.Parameters.Add(pars[i]);
             }
         }
         return(comdAdapter);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemple #3
0
        /// <summary>
        /// 执行存储过程,返回默认输出参数 @Result Varchar(50)
        /// </summary>
        /// <param name="spName"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public string ExecuteOut(string spName, DbParameters pars)
        {
            SqlCommand comd = CreateComd(spName, pars);

            comd.Parameters.Add(new SqlParameter("@Result", SqlDbType.VarChar, 50));
            comd.Parameters["@Result"].Direction = ParameterDirection.Output;

            try
            {
                OpenConn(ref comd);
                comd.ExecuteNonQuery();
                object o = comd.Parameters["@Result"].Value;
                CloseConn(ref comd);

                return((o == null) ? "" : o.ToString());
            }
            catch (Exception ex)
            {
                CloseConn(ref comd);
                throw new Exception(ex.Message);
            }
        }
Exemple #4
0
        /// <summary>
        /// 执行SQL 返回默认输出参数ReturnValue
        /// </summary>
        /// <param name="sqlStr"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public string ExecuteSqlReturn(string sqlStr, DbParameters pars)
        {
            SqlCommand comd = CreateSqlComd(sqlStr, pars);

            comd.Parameters.Add(new SqlParameter("ReturnValue", SqlDbType.VarChar, 50));
            comd.Parameters["ReturnValue"].Direction = ParameterDirection.ReturnValue;

            //comd.Parameters.Add(new SqlParameter("ReturnValue",SqlDbType.Int,4, ParameterDirection.ReturnValue, false, 0, 0,String.Empty, DataRowVersion.Default, null));

            try
            {
                OpenConn(ref comd);
                comd.ExecuteNonQuery();
                object o = comd.Parameters["ReturnValue"].Value;
                CloseConn(ref comd);

                return((o == null) ? "" : o.ToString());
            }
            catch (Exception ex)
            {
                CloseConn(ref comd);
                throw new Exception(ex.Message);
            }
        }
Exemple #5
0
        /// <summary>
        /// 执行sql语句,返回第一个值
        /// </summary>
        /// <param name="sqlStr"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public int ExecuteSqlInt(string sqlStr, DbParameters pars)
        {
            SqlCommand comd = CreateSqlComd(sqlStr, pars);

            return(ToExecuteInt(comd));
        }
Exemple #6
0
        /// <summary>
        /// 执行存储过程,返回执行条数
        /// </summary>
        /// <param name="spName"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public int Execute(string spName, DbParameters pars)
        {
            SqlCommand comd = CreateComd(spName, pars);

            return(ToExecute(comd));
        }
Exemple #7
0
        /// <summary>
        /// 执行SQL语句,返回Scalar对象
        /// </summary>
        /// <param name="sqlStr"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public object CreateSqlScalar(string sqlStr, DbParameters pars)
        {
            SqlCommand comd = CreateSqlComd(sqlStr, pars);

            return(GetScalar(comd));
        }
Exemple #8
0
        /// <summary>
        /// 执行存储过程,返回scalar对象
        /// </summary>
        /// <param name="spName"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public object CreateScalar(string spName, DbParameters pars)
        {
            SqlCommand comd = CreateComd(spName, pars);

            return(GetScalar(comd));
        }
Exemple #9
0
        /// <summary>
        /// 执行SQL语句,返回dt对象
        /// </summary>
        /// <param name="sqlStr"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public DataTable CreateSqlDataTable(string sqlStr, DbParameters pars)
        {
            SqlDataAdapter adapter = CreateSqlAdapter(sqlStr, pars);

            return(GetDataTable(adapter));
        }
Exemple #10
0
        /// <summary>
        /// 执行存储过程,返回dt对象
        /// </summary>
        /// <param name="spName"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public DataTable CreateDataTable(string spName, DbParameters pars)
        {
            SqlDataAdapter adapter = CreateAdapter(spName, pars);

            return(GetDataTable(adapter));
        }
Exemple #11
0
        /// <summary>
        /// 执行SQL语句,返回SqlDataReader对象
        /// </summary>
        /// <param name="sqlStr"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public SqlDataReader CreateSqlDataReader(string sqlStr, DbParameters pars)
        {
            SqlCommand comd = CreateSqlComd(sqlStr, pars);

            return(GetDataReader(comd));
        }
Exemple #12
0
        /// <summary>
        /// 执行存储过程,返回SqlDataReader对象
        /// </summary>
        /// <param name="spName"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public SqlDataReader CreateDataReader(string spName, DbParameters pars)
        {
            SqlCommand comd = CreateComd(spName, pars);

            return(GetDataReader(comd));
        }