日期:2014-05-18  浏览次数:20528 次

接收存储过程返回字符串
存储过程代码
SQL code

ALTER  PROCEDURE p_UpdateTree(
@MenuName nvarchar(50),
@MenuFather nvarchar(50),
@MenuGroup nvarchar(50),
@New_MenuName nvarchar(50),
@NewMenuAddress char(60),
@MenuShow bit,
@RValue nvarchar(10) output
)
AS
SET NOCOUNT ON

Update ControlTree Set MenuName=@New_MenuName,MenuAddress=@NewMenuAddress,MenuShow=@MenuShow
Where  MenuName=@MenuName AND MenuFather=@MenuFather AND MenuGroup= @MenuGroup
IF @@ROWCOUNT>0 
    begin
        set @RValue='OK'
    end
    
ELSE
    begin
        set @RValue='Failed'
    end    
select @RValue
GO



程序接收代码
VB.NET code

Public Function UpdateTree(ByVal MenuName As String, ByVal MenuFather As String, ByVal MenuGroup As String, ByVal New_MenuName As String, ByVal NewMenuAddress As String, ByVal MenuShow As Integer) As Boolean
        Dim SqlCon As New SqlConnection
        SqlCon = Consql()
        Dim SqlComm As New SqlCommand("p_UpdateTree", SqlCon)
        If SqlCon.State Then
            Try
                With SqlComm
                    .CommandType = CommandType.StoredProcedure
                    .Parameters.Add(New SqlParameter("@MenuName", MenuName))
                    .Parameters.Add(New SqlParameter("@MenuFather", MenuFather))
                    .Parameters.Add(New SqlParameter("@MenuGroup", MenuGroup))
                    .Parameters.Add(New SqlParameter("@New_MenuName", New_MenuName))
                    .Parameters.Add(New SqlParameter("@NewMenuAddress", NewMenuAddress & " "))
                    .Parameters.Add(New SqlParameter("@MenuShow", MenuShow))
                    .Parameters.Add(New SqlParameter("@RValue", "5"))
                    .Parameters("@RValue").Direction = ParameterDirection.Output
                    .ExecuteNonQuery()
                End With
                Dim i As String
                i = SqlComm.Parameters("@RValue").Value.ToString.Trim()'这里是用来调试模式看返回值,总是返回空
                If String.Equals(SqlComm.Parameters("@RValue").Value.ToString.Trim(), "OK") Then
                    Return True
                Else
                    Return False
                End If
            Catch ex As Exception

            Finally
                SqlComm.Dispose()
                If SqlCon.State Then SqlCon.Close()
                SqlCon.Dispose()
            End Try
        Else
            HttpContext.Current.Response.Write("打开数据库失败。请与管理员联系!")
            HttpContext.Current.Response.End()
        End If



存储过程我用查询分析器调试 完全正常 可以输出 OK 和Failed
但是用程序来接收返回值的时候,老是返回的空值。请大家帮忙看看是哪的问题
谢谢!!

------解决方案--------------------
.Parameters.Add(New SqlParameter("@RValue", "5")) //老是感觉好象不对劲

你改为看看
.Parameters.Add(New SqlParameter("@RValue", SqlDbType.NVarChar,10))