Passing uniqueidentifier parameter to Stored Procedure

风流意气都作罢 提交于 2019-12-08 17:28:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!