在服务资源管理器里执行存储过程,正常!以下是执行后显示的信息。@RV=15。但在VS解决方案里面测试却报错,test()函数最底行异常——“未将对象引用设置到对象的实例”。查看后发现paramOut.Value参数值为null! -------------------------------------------------------------------------------------------​  正在运行 [dbo].[Sp_GetFilmInfo] ( @id = 2, @RV = 10 ).                                                                                                                                                                                                                               没有行受影响。(返回 1 行)@RV = 15@RETURN_VALUE = 完成 [dbo].[Sp_GetFilmInfo] 运行。​ ---------------------------------------------------------------------------------------------以下是C#编写的存储过程文件名:Sp_GetFilmInfo.cs---------------------------------------------------------------------------------------------​ [Microsoft.SqlServer.Server.SqlProcedure]     public static void Sp_GetFilmInfo(SqlInt32 id,out SqlInt32 RV)    {        // 在此处放置代码        SqlConnection conn = new SqlConnection("context connection=true");        SqlCommand cmd = new SqlCommand();        conn.Open();        cmd.Connection = conn;        cmd.CommandText = "select * from Film where id=@id";        SqlParameter param = new SqlParameter("@id",id);        cmd.Parameters.Add(param);        SqlDataReader dt = cmd.ExecuteReader();        SqlContext.Pipe.Send(dt);        RV = 15;                                                 //设置输出参数为15        cmd.Dispose();        conn.Close();        dt.Close(); 
​    }​  ----------------------------------------------------------------------------------------------以下是调试存储过程函数;功能:输出@RV 这个参数----------------------------------------------------------------------------------------------  public string test()        {            SqlCommand cmd = new SqlCommand();             SqlParameter param1 = new SqlParameter("@id", 2);//查找ID为2的记录,此记录存在            cmd.Parameters.Add(param1); 
​            SqlParameter paramOut = new SqlParameter("@RV",SqlDbType.Int, 10);             paramOut.Direction = ParameterDirection.Output;       //设置输出参数            cmd.Parameters.Add(paramOut);                      SqlConnection conn = new SqlConnection(SQLHelper.Con); //连接数据库            conn.Open();            cmd.Connection = conn;            cmd.CommandType = CommandType.StoredProcedure;            cmd.CommandText = StoredProcedureName.Sp_GetFilmInfo.ToString();//获取存储过程名称,StoredProcedureName.Sp_GetFilmInfo为Model里枚举的存储过程名            SqlDataReader dtr = cmd.ExecuteReader();                        return paramOut.Value.ToString();        } 
​​