将uniqueidentifier参数传递给存储过程

时间:2022-01-23 10:11:32

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

我试图使用以下代码将uniqueidentifier参数传递给存储过程:

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?

我不断收到错误,但是说该程序无法从字符串转换为GUID。我错误地传递了这个值吗?

2 个解决方案

#1


25  

Try this

尝试这个

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

#2


7  

A unique identifier is a GUID. so it's a different object type to your string.

唯一标识符是GUID。所以它是你的字符串的不同对象类型。

You need

你需要

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

#1


25  

Try this

尝试这个

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

#2


7  

A unique identifier is a GUID. so it's a different object type to your string.

唯一标识符是GUID。所以它是你的字符串的不同对象类型。

You need

你需要

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