Generate a new guid

  • Thread starter Thread starter Jason L James
  • Start date Start date
J

Jason L James

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.
 
Guid.NewGuid()

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.
 
* (e-mail address removed)-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.
 
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
 
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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top