Passing a uniqueidentifier parameter to a stored procedure

I am trying to pass a uniqueidentifier parameter to a stored procedure using the following code:

myCommand.Parameters.Add("@BlogID", SqlDbType.UniqueIdentifier).Value = "96d5b379-7e1d-4dac-a6ba-1e50db561b04";

I still get the error message, but cannot convert from string to GUID. Am I passing the value wrong?

+5
source share
2 answers

try it

myCommand.Parameters.Add("@BlogID", SqlDbType.UniqueIdentifier).Value = new Guid("96d5b379-7e1d-4dac-a6ba-1e50db561b04");
+22
source

Unique identifier is a GUID . so this is a different type of object for your string.

You need

myCommand.Parameters.Add("@BlogID", SqlDbType.UniqueIdentifier).Value = 
                                        new Guid("96d5b379-7e1d-4dac-a6ba-1e50db561b04");
+6
source

All Articles