472,965 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,965 software developers and data experts.

GUID from SQL Uniqueidentifier -> Empty?!

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
1 9085
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Ilija_G | last post by:
Hi, Is there any replace for "Select @@identity" that could return "just inserted" GUID as a primary key? Has anyone tested what's faster, working with Guid or Autonumber ?
2
by: Carl | last post by:
Hi, I do have one dataset from SQL server with a field (bound) to Textbox called txtID , this field is of type uniqueidentifier. From the doc, they say the equivalent is GUID in dot net, ...
3
by: Jeffry van de Vuurst | last post by:
Hi, I'm working with Guids as the primary key of some of my tables. In my code, I'm working with those Guids. Now I was wondering what is the best way to work with Guids (in terms of...
3
by: Gopal Krish | last post by:
I need to display uniqueidentifier (GUID) from a table in SQL Server into a ASP.NET Web Page (Combo box). I'm using C#. When I tried to display GUIDs in a combo box I get "System.Byte" for all...
5
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of...
4
by: Dean Slindee | last post by:
I would like to use a Guid as a record identifier for to prevent update collisions (not as the key, but as a substitute for a timestamp field). What is the proper way to define storage for a guid...
6
by: AlveenX | last post by:
Hi, I am trying to pick a Guid from a data row using the following code: foreach(DataRow row in MyDataTable.Rows) { (Guid)row }
8
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Vb.net 2005 app I am looking up records in a sql 2005 database and I grab the uniqueidentifier and put it into a variable (gID) of type GUID. When I try to create a new record in a new table...
1
by: Igor | last post by:
Hi I have a drop down list on my page that lists some items returned from a database. Each item has its GUID (or uniqueidentifier). I have to (in code behind of the page) read this GUID, to hand...
16
by: sloan | last post by:
Current Framework 2.0/3.0. ... In Sql Server, there is a way to generate consecutive guid's. newsequentialid. Is there a way to reproduce this type of consecutive guid's in the framework.
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.