Ralado Posted December 25, 2019 at 11:32 PM Report Share #616920 Posted December 25, 2019 at 11:32 PM estou com erro ao filtrar dados do banco aparece este erro You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IFNULL(est.Quantidade, 0) AS Quantidade FROM tb_produto prod INNER JOIN ' at line 1 meu codigo esta assim... public List<ProdutoDTO> Listar() { List<ProdutoDTO> lProdutos = new List<ProdutoDTO>(); string lsql = string.Empty; DataTable ldataTable; lsql = " SELECT "; lsql += " prod.IdProduto, "; lsql += " prod.Nome, "; lsql += " prod.CodProduto, "; lsql += " prod.Descricao, "; lsql += " prod.Marca, "; lsql += " prod.ValorCusto, "; lsql += " prod.ValorVenda, "; lsql += " prod.DataCadastro, "; lsql += " fun.Nome AS NomeCadastrante, "; lsql += " fun.IdFuncionario AS IdFuncionario, "; lsql += " cat.Nome AS NomeCategoria, "; lsql += " cat.IdCategoria AS IdCategoria, "; lsql += " IFNULL(est.localizacao, 0) AS localizacao "; lsql += " IFNULL(est.Quantidade, 0) AS Quantidade "; lsql += " FROM "; lsql += " tb_produto prod "; lsql += " INNER JOIN "; lsql += " tb_funcionario fun ON fun.IdFuncionario = prod.IdFuncionario "; lsql += " INNER JOIN "; lsql += " tb_categoria cat ON cat.IdCategoria = prod.IdCategoria "; lsql += " LEFT JOIN "; lsql += " tb_estoque est ON est.IdProduto = prod.IdProduto "; ldataTable = lAcessoDados.ExecutarConsulta(CommandType.Text, lsql); foreach (DataRow item in ldataTable.Rows) { ProdutoDTO lProduto = new ProdutoDTO() { IdProduto = item["IdProduto"].ToInt(), Nome = item["Nome"].ToString(), CodProduto = item["CodProduto"].ToString(), Descricao = item["Descricao"].ToString(), Marca = item["Marca"].ToString(), ValorCusto = item["ValorCusto"].ToDecimal(), ValorVenda = item["ValorVenda"].ToDecimal(), DataCadastro = item["DataCadastro"].ToDateTime(), }; lProduto.Cadastrante.IdFuncionario = item["IdFuncionario"].ToInt(); lProduto.Cadastrante.Nome = item["NomeCadastrante"].ToString(); lProduto.Categoria.IdCategoria = item["idCategoria"].ToInt(); lProduto.Categoria.Nome = item["NomeCategoria"].ToString(); lProduto.Estoque.localizacao = item["localizacao"].ToString(); lProduto.Estoque.Quantidade = item["Quantidade"].ToInt(); lProdutos.Add(lProduto); } return lProdutos; } Link to comment Share on other sites More sharing options...
antseq Posted December 26, 2019 at 09:43 AM Report Share #616923 Posted December 26, 2019 at 09:43 AM Citação lsql += " IFNULL(est.localizacao, 0) AS localizacao "; lsql += " IFNULL(est.Quantidade, 0) AS Quantidade "; do que vejo, falta-lhe uma "virgula" a seguir a "AS localização": lsql += " IFNULL(est.localizacao, 0) AS localizacao, "; lsql += " IFNULL(est.Quantidade, 0) AS Quantidade "; cps, 2 Report Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now