Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting SQL Server uniqueidentifier to .NET Guid type
Message
From
28/03/2009 12:42:36
 
 
To
24/03/2009 10:35:28
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 3.0
Database:
MS SQL Server
Miscellaneous
Thread ID:
01391015
Message ID:
01391974
Views:
58
I use guids a lot (mostly because of VFP data that used them extensively that has been converted)

FWIW one thing to remember is you never want a clustered index on a UID. Inserts require a lot of thrashing. There are algorithms to produce sequential UIDs that get around this problem and SQL 2008 has newsequentialid() if you are getting keys on the back end.

>Hopefully somebody can provide a better way of doing this. The UserId field in my datareader is uniqueidentifier type in SQL Server.
>
>
>Guid UserId = new Guid(Convert.ToString(reader["UserId"]));
>
>
>Would this be better (more efficent):
>
>Guid UserId  = (Guid) reader["UserId"];
>
>
>Overall, is it better to use the System.Convert method or do a cast like the second example?


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Previous
Reply
Map
View

Click here to load this message in the networking platform