我的SQL2000存储过程如下:
alter procedure dbo.updateSiteConfig
(
@output NVarChar(50) output
)
AS
begin
select @output=aa from myTable where id=1
end
return

-----------------------------------------
这是的C#程序代码,该代码调用了此存储过程
public override string updateSiteConfig(FunctionCategory functionCategory)
{
using ( SqlConnection myConnection = GetSqlConnectionString() )  // 此连接是无错的.
{
SqlCommand myCommand = new SqlCommand(DatabaseOwner + ".updateSiteConfig", myConnection);
myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.Add("@output", SqlDbType.NVarChar, 50);
myCommand.Parameters["@output"].Direction = ParameterDirection.Output; myConnection.Open();
myCommand.ExecuteNonQuery();
string bb = myCommand.Parameters["@output"].Value.ToString();
myConnection.Close(); return bb;
}
}----------------------------------------
问题:我运行此程序后,得到的bb值为空值,请问问题是出错在哪儿? 特别说明,select aa from myTable where id=1 绝对有返回值.
我编译此程序不会报错,如果按照正常的运行的话,bb将会得到SQL语句select aa from myTable where id=1的值.

解决方案 »

  1.   

    试试public override string updateSiteConfig(FunctionCategory functionCategory)
    {
    using ( SqlConnection myConnection = GetSqlConnectionString() ) 
    {
    SqlCommand myCommand= new SqlCommand(DatabaseOwner + ".updateSiteConfig", myConnection);
    myCommand.CommandType= CommandType.StoredProcedure;
    myCommand.Parameters.Add("@output", SqlDbType.NVarChar, 50);
    myCommand.Parameters["@output"].Direction= ParameterDirection.Output;
    myCommand.Parameters["@output"].Value="test";//加这句
    myConnection.Open();
    myCommand.ExecuteNonQuery();
    string bb = myCommand.Parameters["@output"].Value.ToString();
    myConnection.Close();
    return bb;
    }
    }
      

  2.   

    to: singlepine(小山) 
    -----------------------
    我加了您说的那句之后,结果还是无值,也就是依然为空值.晕.本来加了你那句后,应该是得到"test"这个值吧?可是依然没有这个值.晕.这问题出在哪儿了?晕.
      

  3.   

    alter procedure dbo.updateSiteConfig
    (
    @output NVarChar(50) output
    )
    AS
    begin
    select @output=IsNull(aa,'abc') from myTable where id=1
    end
    return
      

  4.   

    to: withjun(withjun)
    ----------------------------
    你给的方法我刚刚试过了,也无效.5555555555继续崩溃中,大家再帮我看一下.下个这个是报错:
    参数 2: String 类型的“@OutputClassName”,Size 属性具有无效大小值: 0
      

  5.   

    alter procedure dbo.updateSiteConfig
    (
    @output NVarChar(50) output
    )
    AS
    begin
         return select @output=aa from myTable where id=1
    end
      

  6.   

    下面这个是报错:
    参数 2: String 类型的“@OutputClassName”,Size 属性具有无效大小值: 0 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 参数 2: String 类型的“@OutputClassName”,Size 属性具有无效大小值: 0源错误: 
    行 972:
    行 973: myConnection.Open();
    行 974: myCommand.ExecuteNonQuery();
    行 975: string outputClassName = myCommand.Parameters["@OutputClassName"].Value.ToString();
    行 976: myConnection.Close();
     
    -----------------------------------------------
    --------------------------------------------
    简单的描述报错信息:
    参数 2: String 类型的“@OutputClassName”,Size 属性具有无效大小值: 0
      

  7.   

    string outputClassName = myCommand.Parameters["@OutputClassName"].Value.ToString();
    这句是从哪来??
    怎么不是:
    string outputClassName = myCommand.Parameters["@output"].Value.ToString();
    ?????
      

  8.   

    sql语句返回是否是唯一值?或者返回值超过变量大小
      

  9.   

    to: withjun(withjun)
    ------------------------
    之所以不一样,那是因为顶楼的例子是我自己写的,是一个简化的程序,以便拿出来让大家看得更明白.
    上面的报错不一样是因为我实际的程序跟例子不一样,所以才会参数不一样.to: hp44() 
    ---------------------
    一定是返回唯一值.