Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting SQL Server uniqueidentifier to .NET Guid type
Message
 
 
À
24/03/2009 12:22:28
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 3.0
Database:
MS SQL Server
Divers
Thread ID:
01391015
Message ID:
01391067
Vues:
44
>>>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?
>>
>>The two statements are not equavalent. In the first I think you're creating a new Guid. The last statement just takes the existing value and assigns it to a variable. I would assume the second is more efficient.
>
>I have confirmed that both statements are equivalent.

Great, thanks. I guess I was wrong then.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform