1
I’m making a list of customers, but is returning this error:
System.Argumentexception: 'Column 'Cpf_cpnj' does not Belong to table .'
This column, Cpf_Cnpj
, is in my database:
I can’t solve this problem...
Class code model
:
using DnxVendas.Uteis;
using System.Collections.Generic;
using System.Data;
namespace DnxVendas.Models
{
public class Cliente
{
public string ClienteId { get; set; }
public string Nome { get; set; }
public string Cpf_Cnpj { get; set; }
public string Email { get; set; }
public string Senha { get; set; }
public List<Cliente> ListarTodosClientes()
{
List<Cliente> lista = new List<Cliente>();
Cliente item;
DAL objDAL = new DAL();
string sql = "Select ClienteId, Nome, Cpf_Cnpj, Email, Senha From Cadastro.Clientes order by Nome asc";
DataTable dt = objDAL.RetDaaTable(sql);
for (int i = 0; i < dt.Rows.Count; i++)
{
item = new Cliente
{
ClienteId = dt.Rows[i]["ClienteId"].ToString(),
Nome = dt.Rows[i]["Nome"].ToString(),
Cpf_Cnpj = dt.Rows[i]["Cpf_Cpnj"].ToString(), // Problema ocorre nesta linha
Email = dt.Rows[i]["Email"].ToString(),
Senha = dt.Rows[i]["Senha"].ToString()
};
lista.Add(item);
}
return lista;
}
}
}
I’ve circled my own string that makes the query in the database and returns the correct information:
string sql = "Select ClienteId, Nome, Cpf_Cnpj, Email, Senha From Cadastro.Clientes order by Nome asc";
Making explicit emails, Cpfs and people names.
– CypherPotato