问题
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 keep getting an error however saying that the program was unable to convert from string to GUID. Am I passing the value incorrectly?
回答1:
Try this
myCommand.Parameters.Add("@BlogID", SqlDbType.UniqueIdentifier).Value = new Guid("96d5b379-7e1d-4dac-a6ba-1e50db561b04");
回答2:
A unique identifier is a GUID. so it's a different object type to your string.
You need
myCommand.Parameters.Add("@BlogID", SqlDbType.UniqueIdentifier).Value =
new Guid("96d5b379-7e1d-4dac-a6ba-1e50db561b04");
来源:https://stackoverflow.com/questions/11724614/passing-uniqueidentifier-parameter-to-stored-procedure