Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

I have a stored procedure that has three parameters and I've been trying to use the following to return the results:

context.Database.SqlQuery<myEntityType>("mySpName", param1, param2, param3);

At first I tried using SqlParameter objects as the params but this didn't work and threw a SqlException with the following message:

Procedure or function 'mySpName' expects parameter '@param1', which was not supplied.

So my question is how you can use this method with a stored procedure that expects parameters?


1 Answer

0 votes
by (40.7k points)

You should supply the SqlParameter instances in the following way:


    "mySpName @param1, @param2, @param3",

    new SqlParameter("param1", param1),

    new SqlParameter("param2", param2),

    new SqlParameter("param3", param3));

Related questions

Browse Categories