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

.net调用存储过程的返回值的问题
存储过程的代码
ALTER PROCEDURE dbo.test 
  @out_aft_nunn INT OUTPUT,
  @out_mObjectNo INT OUTPUT

AS
begin
   
  set @out_aft_nunn = 112
  set @out_mObjectNo =456
end
程序调用的代码 Dim conn As New SqlClient.SqlConnection(Me.ConnectionString)
  Try
  Dim myCmd As New SqlClient.SqlCommand

  myCmd.CommandType = CommandType.StoredProcedure
  myCmd.CommandTimeout = 0
  myCmd.CommandText = "dbo.test "
  myCmd.CommandTimeout = 0
  myCmd.Connection = conn
  myCmd.Connection.Open()
  Dim myDap As New SqlClient.SqlDataAdapter(myCmd)

  myDap.SelectCommand.Parameters.Add(("@out_aft_nunn"), SqlDbType.Int).Value = 5
  myDap.SelectCommand.Parameters.Add(("@out_mObjectNo"), SqlDbType.Int).Value = 6

  myCmd.ExecuteNonQuery()
   
  Dim obj2 As Integer = CInt(myCmd.Parameters(1).Value)
  Dim obj1 As Integer = CInt(myCmd.Parameters("@out_mObjectNo").Value)
   
  Catch ex As Exception
  Throw
  Finally
  conn.Close()
  End Try

  'Return "0"
  End Function
以上的代码,调用的存储过程中有多个出参,用.net调用取得的值为什么是我入参的值呢

------解决方案--------------------
VB.NET code
.Direction = ParameterDirection.Output