Posted by: Cirilo Meggiolaro | 10/29/2008

Tip of the day #15 – Converting string to Sql Server Guid data type

I worked some time ago in a web application where a uniqueidentifier data type was used as primary key for the tables.

The application used to store the value as a string and to update a record in the database, the guid was the key on the T-SQL where clauses.

Ok, but how do we convert a string to a format that SQL Server will understand?

Available under the System.Data.SqlTypes namespace, the static Parse method from the SqlGuid structure executes the conversion since the string contains the specific Guid format for example: {E13D5C51-9D08-4d56-978F-5FD388A9AB8C}

How to…

SqlGuid.Parse(myString);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: