By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

GUID from SQL Uniqueidentifier -> Empty?!

P: n/a
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("ConnectionStri ng")
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").Val ue,
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
My understanding is that system.GUID is for creating a new GUID string. I
don't think(in my limited knowledge) that is can store an outside guid. if
you look at the constructors I do not believe there is an option for a full
guid string as input.
--
--Eric Cathell, MCSA
"Scott M. Lyon" <sc******************@rapistan.BLUE.com> wrote in message
news:ec**************@TK2MSFTNGP14.phx.gbl...
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("ConnectionStri ng")
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").Val ue,
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

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.