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

Generate a new guid

P: n/a
Hi all,

is there a method or property of a class that will
return a GUID in VB.NET that I can use as
the PK of my DB. I do not want SQL to generate
it as I can not then use

SELECT @@IDENTITY to retrieve it.

I want to try and mimic the functionality of

newID()

that SQL server has.

Thanks,

Jason.
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Guid.NewGuid()

"Jason L James" <ja***@no-spam.dive-master.org> wrote in message
news:41***************@news.demon.co.uk...
Hi all,

is there a method or property of a class that will
return a GUID in VB.NET that I can use as
the PK of my DB. I do not want SQL to generate
it as I can not then use

SELECT @@IDENTITY to retrieve it.

I want to try and mimic the functionality of

newID()

that SQL server has.

Thanks,

Jason.
Nov 21 '05 #2

P: n/a
* ja***@no-spam.dive-master.org (Jason L James) scripsit:
is there a method or property of a class that will
return a GUID in VB.NET that I can use as
the PK of my DB. I do not want SQL to generate
it as I can not then use

SELECT @@IDENTITY to retrieve it.

I want to try and mimic the functionality of

newID()


Take a look at the 'SqlGuid' class and the 'Guid.NewGuid' method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

P: n/a
I ran into this exact same problem in which case the GUID was generated
after the procedure had been called.

select @@IDENTITY will not return the guid because you cannot have a sqlguid
(uniquieidentifier in T-SQL) as an identifier row (at least as far as SQL is
concerned).

I wrote my stored procedures to have both an identity column and a row guid
problem. the reason I use row guids is mainly for users ( a little social
eng if you will), I don't like sequences..

however, I do use them.. i.e, I have a stored procedure that does

Insert into MyTable (name1, name2, name3) values (value1, value2, value3)

then

SELECT gRowID FROM myTable Where iID = SCOPE_IDENTITY()

tends to work a little better and I get my GUID.

where iID is an identity type (of decimal, big number, but gives you a lot
fo flexibility) and I hide it from the user. its an extra T-SQL step, but I
have yet to find a better way to do it other than providing my own GUID.

HTH,
CJ

"Jason L James" <ja***@no-spam.dive-master.org> wrote in message
news:41***************@news.demon.co.uk...
Hi all,

is there a method or property of a class that will
return a GUID in VB.NET that I can use as
the PK of my DB. I do not want SQL to generate
it as I can not then use

SELECT @@IDENTITY to retrieve it.

I want to try and mimic the functionality of

newID()

that SQL server has.

Thanks,

Jason.

Nov 21 '05 #4

P: n/a
CJ,

can I do this using SQL CE? I don't think I can!

Any ideas?

Thanks,

Jason.

P.S. At the moment I am considering returning to int IDs and make
things work using the replication options of SQL 2K.

On Fri, 27 Aug 2004 09:38:51 -0500, "CJ Taylor" <[cege] at [tavayn]
dit commmmm> wrote:
I ran into this exact same problem in which case the GUID was generated
after the procedure had been called.

select @@IDENTITY will not return the guid because you cannot have a sqlguid
(uniquieidentifier in T-SQL) as an identifier row (at least as far as SQL is
concerned).

I wrote my stored procedures to have both an identity column and a row guid
problem. the reason I use row guids is mainly for users ( a little social
eng if you will), I don't like sequences..

however, I do use them.. i.e, I have a stored procedure that does

Insert into MyTable (name1, name2, name3) values (value1, value2, value3)

then

SELECT gRowID FROM myTable Where iID = SCOPE_IDENTITY()

tends to work a little better and I get my GUID.

where iID is an identity type (of decimal, big number, but gives you a lot
fo flexibility) and I hide it from the user. its an extra T-SQL step, but I
have yet to find a better way to do it other than providing my own GUID.

HTH,
CJ

"Jason L James" <ja***@no-spam.dive-master.org> wrote in message
news:41***************@news.demon.co.uk...
Hi all,

is there a method or property of a class that will
return a GUID in VB.NET that I can use as
the PK of my DB. I do not want SQL to generate
it as I can not then use

SELECT @@IDENTITY to retrieve it.

I want to try and mimic the functionality of

newID()

that SQL server has.

Thanks,

Jason.



Nov 21 '05 #5

P: n/a
Unfortunatly I don't have any experience with SQL CE. Given the way
Microsoft does things, I would be tempted to say yes, however, its a
platform I've only toyed with, and very mildely at that.

does SQL CE support Stored Procedures?

It may be easier to go back to numeric for you, thats up to you. Like I
said, I did it to trick my users so they didn't try to get crafty and break
something. Then again, I'm a really paranoid guy.

HTH,
CJ

"Jason L James" <ja***@no-spam.dive-master.org> wrote in message
news:41***************@news.demon.co.uk...
CJ,

can I do this using SQL CE? I don't think I can!

Any ideas?

Thanks,

Jason.

P.S. At the moment I am considering returning to int IDs and make
things work using the replication options of SQL 2K.

On Fri, 27 Aug 2004 09:38:51 -0500, "CJ Taylor" <[cege] at [tavayn]
dit commmmm> wrote:
I ran into this exact same problem in which case the GUID was generated
after the procedure had been called.

select @@IDENTITY will not return the guid because you cannot have a sqlguid(uniquieidentifier in T-SQL) as an identifier row (at least as far as SQL isconcerned).

I wrote my stored procedures to have both an identity column and a row guidproblem. the reason I use row guids is mainly for users ( a little socialeng if you will), I don't like sequences..

however, I do use them.. i.e, I have a stored procedure that does

Insert into MyTable (name1, name2, name3) values (value1, value2, value3)

then

SELECT gRowID FROM myTable Where iID = SCOPE_IDENTITY()

tends to work a little better and I get my GUID.

where iID is an identity type (of decimal, big number, but gives you a lotfo flexibility) and I hide it from the user. its an extra T-SQL step, but Ihave yet to find a better way to do it other than providing my own GUID.

HTH,
CJ

"Jason L James" <ja***@no-spam.dive-master.org> wrote in message
news:41***************@news.demon.co.uk...
Hi all,

is there a method or property of a class that will
return a GUID in VB.NET that I can use as
the PK of my DB. I do not want SQL to generate
it as I can not then use

SELECT @@IDENTITY to retrieve it.

I want to try and mimic the functionality of

newID()

that SQL server has.

Thanks,

Jason.


Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.