December 18, 2007 at 10:47 pm
Hi All,
Can you please Help.
In my table, i have a unique identifier column as a primary key. My intension is to return the ID as an output parameter but because i cannot use any of the available functions provided by sql 2005 such as @@Identity / Scope IDENTITY(). How can I return the value of the GUID column that has just been created (This is an Identity and Primary column Value).
Any suggestion on how can i get the new created GUID value returned to my c# code?
Is the any function that I may not know that i can use to return a Guid / Uniqueidentifier value?
I'm very new in the sql world, please bear with me if my question is not clear. Please Help..
December 19, 2007 at 1:02 am
Hi,
As far as i know you cannot have the IDENTITY property on a columns which is UNIQUEIDENTIFIER and also PRIMARY KEY.
when inserting the data into the table , first declare a variable for example
DECLARE @id UNIQUEIDENTIFIER
SET @id = newid()
now
insert the the value of the @id variable into the table and at the end of the stored procedure you can return the value of the @id paramter into the C# code.
Regards,
Oana.
January 15, 2010 at 10:53 am
There is another option since you are using c#.
Create the necessary GUIDs before you insert the rows into the table and pass them into the Database.
This way you do not have to rely upon the database default to create the GUID and then pass the results back out.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply