Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how run store procedure in web api c# netcore 6

i want run a store procedure from controller in web api netcore 6 but always give me error 500 , i try multiples solution and always error 500.
I want to send 2 parameters and receive a list

this is the sp

ALTER   PROCEDURE [dbo].[listaProductoPrecio]
@Minimo int,
@Maximo int
AS
BEGIN
    
    Select * from dbo.Productos where PrecioProducto BETWEEN @Minimo AND @Maximo
END

and next is the controller

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[HttpGet]
        [Route("api/listaEntrePrecios")]
        public IEnumerable<Producto> listaEntrePrecios(int minimo, int maximo)
        {

            var parameters = new[]
            {
                new SqlParameter("@Minimo",minimo),
                new SqlParameter("@Maximo",maximo)
            };

            var lista = context.productos.FromSqlRaw("EXECUTE listaProductoPrecio @Minimo @Maximo", parameters).ToList();
            return lista;
        }

i do that just for i want try a store procedure in a api, im a newbie programming, help plss

>Solution :

You are simply missing a comma:

"EXECUTE listaProductoPrecio @Minimo @Maximo"

should be

"EXECUTE listaProductoPrecio @Minimo, @Maximo"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading