C # ASP.NET Search method by parameter returning Error 500 Internal Server Error

0

Good afternoon, I'm having a problem with a method that fetches the products and returns a specific one according to the last code. I am getting the 500 Internal Server Error error when I try to use the url link to call it. However the search for the entire product list works naturally. Any idea? follow code

Code:

namespace ControleDeEstoqueAPI_.Controllers
{

    public class ProdutoConsultController : ApiController
    {

        [Route("api/Produto")]
        // GET api/ProdutoConsult
        public ObjectResult<uspConsultarProduto_Result> Get()
        {
            ControleDeEstoqueEntities entity = new ControleDeEstoqueEntities();
            var result = entity.uspConsultarProduto(null);
            return result;
        }

        [Route("api/Produto/{cod}")]
        // GET api/ProdutoConsult/5
        public List<produto> Get(int cod)
        {
            ControleDeEstoqueEntities entity = new ControleDeEstoqueEntities();
            List<produto> MyList = new List<produto>();
            var result = from produto in entity.produto where produto.pro_cod == cod select produto;
            MyList.AddRange(result);

            return MyList;
        }

    }
}
    
asked by anonymous 03.12.2016 / 21:50

1 answer

0

Changing the body of the method was enough, I did so

Code:

[Route("api/Produto/{cod}")]
// GET api/ProdutoConsult/5
public DataTable Get(int cod)
{
        SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=ControleDeEstoque;Integrated Security=True");
        DataTable tabela = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter("Select * from Produto where pro_cod like '%" + cod + "%'", con);
        da.Fill(tabela);
        return tabela;
}

It's returning the right result to me.

    
03.12.2016 / 22:03