PDA

Click to See Complete Forum and Search --> : Capture the return/output value from Stored Procedure


htang619
Aug 7th, 2002, 04:21 PM
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.:confused: