Example #1
0
        /// <summary>
        /// 执行存储过程并返回受影响行数,同时获得1个Output参数的值
        /// </summary>
        /// <typeparam name="T">Output参数的CLR类型</typeparam>
        /// <param name="conn">链接</param>
        /// <param name="name">存储过程名</param>
        /// <param name="outparam">第一个参数,即output参数</param>
        /// <param name="parameterValues">其余的参数列表</param>
        /// <returns>受影响行数</returns>
        public static long ExecuteNonQuery <T>(SqlConnection conn, String name, out T outparam, params object[] parameterValues)
        {
            outparam = default(T);

            SqlParameter[] parameters     = SqlHelperParameterCache.GetSpParameterSet(conn.ConnectionString, name);
            ArrayList      paramValueList = new ArrayList();

            paramValueList.Add(outparam);
            paramValueList.AddRange(parameterValues);
            AssignParameterValues(parameters, paramValueList.ToArray());

            long returnValue = ExecuteNonQuery(conn, name, parameters);

            if (parameters[0].Direction == ParameterDirection.InputOutput || parameters[0].Direction == ParameterDirection.Output)
            {
                outparam = (T)parameters[0].Value;
            }

            return(returnValue);
        }
Example #2
0
 public static SqlDataReader ExecuteReader(SqlConnection conn, SqlTransaction tran, String name, params object[] parameterValues)
 {
     SqlParameter[] parameters = SqlHelperParameterCache.GetSpParameterSet(conn.ConnectionString, name);
     AssignParameterValues(parameters, parameterValues);
     return(ExecuteReader(tran, name, parameters));
 }