Results 1 to 1 of 1

Thread: Capture the return/output value from Stored Procedure

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Location
    Pleasanton, CA
    Posts
    1

    Exclamation Capture the return/output value from Stored Procedure

    I have the following code to invoke a stored procedure and this SP does nothing but create a SessionID and output/return it back to the VB7 and then display it in a text box.

    Dim scmd As New SqlCommand("ezud_admin_create_sessionid", SqlConnection)
    Dim sda As New SqlDataAdapter(scmd)
    Dim dsSessionid As New DataSet()

    scmd.CommandType = CommandType.StoredProcedure
    SqlConnection.Open()
    With scmd.Parameters
    .Add(New SqlParameter("@sessionid", SqlDbType.VarChar)).Direction = ParameterDirection.Output
    End With
    sda.Fill(dsSessionid)
    txtSessionId.Text = CType(scmd.Parameters("@sessionid").Value, Char).ToString
    SqlConnection.Close()
    scmd.Dispose()
    SqlConnection.Dispose()

    However, the debugger keeps giving me this msg:

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: Parameter 0: '@sessionid' of type: String, the property Size has an invalid size: 0

    Source Error:


    Line 191: 'cmSQL.ExecuteNonQuery()
    Line 192: 'DataGrid2.DataBind()
    Line 193: sda.Fill(dsSessionid)
    Line 194: txtSessionId.Text = CType(scmd.Parameters("@sessionid").Value, Char).ToString
    Line 195: SqlConnection.Close()


    Line 193: sda.Fill(dsSessionid) is highlighted for the error. It seems that @sessionid is null after the SP is invoked. And it did not return anything to @sessionid.

    Here is the SP(very simple one):

    CREATE PROCEDURE dbo.ezud_admin_create_sessionid @sessionid varchar(32) OUTPUT
    AS
    select @SessionID = convert(varchar(19),getdate(),120)+' '+ cast(@@spid as varchar(5))
    GO

    I am following the VB7 docs. Can anyone tell me what went wrong here. Thanks in advance.
    Last edited by htang619; Aug 8th, 2002 at 05:40 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width