Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing uniqueidentifier parameter to 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 keep getting an error however saying that the program was unable to convert from string to GUID. Am I passing the value incorrectly?

like image 767
TheGateKeeper Avatar asked Jul 30 '12 15:07

TheGateKeeper


People also ask

Can we pass parameter in stored procedure?

SQL Stored Procedures for SQL Server So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it. You can also pass parameters to a stored procedure, so that the stored procedure can act based on the parameter value(s) that is passed.

Can pass 3 types of parameters to stored procedures What are they?

As a program, a stored procedure can take parameters. There are three types of parameters: IN, OUT and INOUT.

Can we pass table variable as parameter in stored procedure?

You cannot pass table-valued parameters to CLR user-defined functions. Table-valued parameters can only be indexed to support UNIQUE or PRIMARY KEY constraints. SQL Server does not maintain statistics on table-valued parameters. Table-valued parameters are read-only in Transact-SQL code.

How do you use Uniqueidentifier?

Create a variable of uniqueidentifier data type. Type the below code in SSMS and execute. DECLARE @guid uniqueidentifier = NEWID(); SELECT @guid as 'GUID'; Here we created a variable named guid of data type uniqueidentifier.


1 Answers

Try this

myCommand.Parameters.Add("@BlogID", SqlDbType.UniqueIdentifier).Value = new Guid("96d5b379-7e1d-4dac-a6ba-1e50db561b04");
like image 195
Daniel A. White Avatar answered Oct 05 '22 18:10

Daniel A. White