0
I have an application used layers and I have a question...
When the UI layer requests multiple records, it would be better to load the whole into a list<> or use the datatable?
Today I use it as follows:
public List<ClienteModel> Listagem(string filtro)
{
try
{
AbrirConexao();
if (filtro == "")
{
Cmd = new SqlCommand("Select * from Clientes INNER JOIN Estados ON Clientes.id_uf = Estados.Id", Con);
}
else
{
//Usando Filtro - A Implementar
}
Dr = Cmd.ExecuteReader();
List<ClienteModel> lista = new List<ClienteModel>();
while (Dr.Read())
{
ClienteModel c = new ClienteModel();
c.Id = Convert.ToInt32(Dr["id"]);
c.CodigoCliente = Convert.ToInt32(Dr["codcli"]);
c.Nome = Convert.ToString(Dr["nome"]);
c.Endereco = Convert.ToString(Dr["endereco"]);
c.NumeroEndereco = Convert.ToString(Dr["nr"]);
c.Bairro = Convert.ToString(Dr["bairro"]);
c.Cidade = Convert.ToString(Dr["cidade"]);
c.Cep = Convert.ToString(Dr["cep"]);
c.Estado.id = Convert.ToInt32(Dr["id_uf"]);
c.Estado.sigla = Convert.ToString(Dr["sigla"]);
c.Observacoes = Convert.ToString(Dr["obs"]);
lista.Add(c);
}
return lista;
}
catch (Exception ex)
{
throw new Exception("Erro na Listagem dos Clientes.. " + ex.Message);
}
finally
{
FecharConexao();
}
}
How about you ask what the difference is between the two ? " what would be better" fits into a question based on opinion what and outside the scope of the site understands ? I can post an example showing both ways and you can compare and define which is best for your case, but cool and you remove your question from the format based on opinions ,it can be negative or closed >.<
– stringnome
No context has no answer. Both can be very bad depending on the use.
– Maniero
I edited the post.. I was on Cellular and did not have the code.. is more a matter of what would be better even..
– Fabio Zanardo