S
Scott M. Lyon
I've got a stored procedure that takes a few parameters as input parameters,
and one output parameter (a uniqueidentifier).
After the stored procedure call, I need to return that output parameter in a
System.Guid object.
Unfortunately, I'm having zero luck doing this.
Public Function BuildExtract(byval ProjectNumber as string, byval ListNumber
as string) As Guid
Dim connectString As String =
DBConnectionManager.GetInstance.ConnectionString
'ConfigurationSettings.AppSettings("ConnectionString")
Dim cmd As SqlCommand = New SqlCommand
Dim conn As SqlConnection = New SqlConnection(connectString)
Dim param1 As SqlParameter
Dim newGUID As Guid
Dim ReturnValue As Boolean
conn.Open()
cmd.Connection = conn
cmd.CommandText = "BUILD_DATA"
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandTimeout = 0
param1 = New SqlParameter("@project_number", SqlDbType.VarChar, 25)
param1.Value = ProjectNumber
cmd.Parameters.Add(param1)
param1 = New SqlParameter("@list", SqlDbType.VarChar, 50)
param1.Value = ListNumber
cmd.Parameters.Add(param1)
param1 = New SqlParameter("@sessionid", SqlDbType.UniqueIdentifier)
'param1 = New SqlParameter("@sessionid", SqlDbType.VarChar, 50)
param1.Direction = ParameterDirection.Output
cmd.Parameters.Add(param1)
cmd.ExecuteNonQuery()
'newGUID = New System.Guid(CType(cmd.Parameters("@Sessionid").Value,
String))
newGUID = cmd.Parameters("@Sessionid").Value
Return newGUID
End function
But when I do this, every time the GUID that is returned is empty (despite
confirming that the stored procedure is working properly and returning a
uniqueidentifier).
So I tried (as you can see from the commented out lines above) returning it
as a string instead (the sp still has it as a uniqueidentifier). When I did
that, I confirmed that the GUID is coming back properly, but when I tried to
create a new System.Guid using that value, once again I got an empty GUID.
What am I doing wrong?
Thanks!
-Scott
and one output parameter (a uniqueidentifier).
After the stored procedure call, I need to return that output parameter in a
System.Guid object.
Unfortunately, I'm having zero luck doing this.
Public Function BuildExtract(byval ProjectNumber as string, byval ListNumber
as string) As Guid
Dim connectString As String =
DBConnectionManager.GetInstance.ConnectionString
'ConfigurationSettings.AppSettings("ConnectionString")
Dim cmd As SqlCommand = New SqlCommand
Dim conn As SqlConnection = New SqlConnection(connectString)
Dim param1 As SqlParameter
Dim newGUID As Guid
Dim ReturnValue As Boolean
conn.Open()
cmd.Connection = conn
cmd.CommandText = "BUILD_DATA"
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandTimeout = 0
param1 = New SqlParameter("@project_number", SqlDbType.VarChar, 25)
param1.Value = ProjectNumber
cmd.Parameters.Add(param1)
param1 = New SqlParameter("@list", SqlDbType.VarChar, 50)
param1.Value = ListNumber
cmd.Parameters.Add(param1)
param1 = New SqlParameter("@sessionid", SqlDbType.UniqueIdentifier)
'param1 = New SqlParameter("@sessionid", SqlDbType.VarChar, 50)
param1.Direction = ParameterDirection.Output
cmd.Parameters.Add(param1)
cmd.ExecuteNonQuery()
'newGUID = New System.Guid(CType(cmd.Parameters("@Sessionid").Value,
String))
newGUID = cmd.Parameters("@Sessionid").Value
Return newGUID
End function
But when I do this, every time the GUID that is returned is empty (despite
confirming that the stored procedure is working properly and returning a
uniqueidentifier).
So I tried (as you can see from the commented out lines above) returning it
as a string instead (the sp still has it as a uniqueidentifier). When I did
that, I confirmed that the GUID is coming back properly, but when I tried to
create a new System.Guid using that value, once again I got an empty GUID.
What am I doing wrong?
Thanks!
-Scott