>>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?
>
>Big eye roll to me...
>
>Or I could use the build in methods of the reader:
>
>Guid UserId = reader.GetGuid(reader.GetOrdinal("UserId"));
>
I have been using the casting (like in your 2nd example), I don't have any hard proof but I think it is more efficient.
I was not aware of the reader.GetGuid, so that was an eye opener to me too. I'll have to check into that. Thanks for posting the code.
Semper ubi sub ubi.