执行带参数的存储过程的方法II(相对通用)


        IDataParameter[] parameters = new IDataParameter[11];

        parameters[0] = (IDataParameter)Activator.CreateInstance(typeof(SqlParameter), false);
        parameters[0].ParameterName = "@tablename";
        parameters[0].Value = strTable;

        parameters[1] = (IDataParameter)Activator.CreateInstance(typeof(SqlParameter), false);
        parameters[1].ParameterName = "@pageindex";
        parameters[1].Value = currentPage;


        DataTable dt = DABase.RunProcedure("sp_paginationtest", parameters, "@recordcount", out objReturn);

 

/**/
    /// <summary>
    /// 执行存储过程
    /// </summary>
    /// <param name="storedProcName">存储过程名</param>
    /// <param name="parameters">存储过程参数</param>
    /// <param name="parameters">返回变量</param>
    /// <param name="parameters">返回值</param>
    /// <returns>DataTable</returns>
    public static DataTable RunProcedure(string storedProcName, IDataParameter[] parameters, string returnStr,out object returnValue)
    {
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            DataTable dt = new DataTable();
            returnValue = null;
            connection.Open();
            SqlDataAdapter sqlDA = new SqlDataAdapter();
            sqlDA.SelectCommand = BuildQueryCommand(connection, storedProcName, parameters);
            sqlDA.Fill(dt);
            returnValue = sqlDA.SelectCommand.Parameters[returnStr].Value;
            connection.Close();
            return dt;
        }
    } 

posted on 2007-10-19 10:06  LongSky  阅读(250)  评论(0编辑  收藏  举报

导航