Take the 2-minute tour ×

I want to insert a string into a table as a uniqueidentifier type. But when I insert it to the database, it throws an error. How can i convert a string to a uniqueidentifier?

share|improve this question
So... is dsfdsf just a keyboard cough or does it mean something? –  Henk Holterman Aug 31 '11 at 15:09
I guess he me means "in the format like dsfdsf-dfdsf-dfgdsfg" ? –  juFo Apr 17 '12 at 15:43

4 Answers 4

up vote 5 down vote accepted

You can try:

new Guid("string to convert");

But the string will need to be in Guid format already.

share|improve this answer
thanks it worked –  Mahdi_Nine Aug 31 '11 at 15:15

In .Net 4, there's a Guid.TryParse(string, out Guid) which returns bool on success.

share|improve this answer
+1 for your good answer. –  Mahdi_Nine Aug 31 '11 at 15:38
+1 idd for the good addition –  BlackHawkDesign May 9 '12 at 7:50

This is a safe way to attempt parsing a string into a Guid. In my example, input is a string variable from the user:

var myGuid = new Guid();
if (Guid.TryParse(input, out myGuid)) {
    // Parsed OK
share|improve this answer
+1 for your good answer. –  Mahdi_Nine Aug 31 '11 at 15:37

use one of these:



share|improve this answer

Your Answer


