0
I have this user class ADO, where I select to return only: Registration, Name and Accesses and return in a gridView.
public List<Usuario> ObterTotalporMatricula()
{
var lista = new List<Usuario>();
using (var connection = ServiceLocator.ObterConexao())
{
var command = connection.CreateCommand();
command.CommandText = "SELECT MATRICULA,NOME,ACESSOS FROM USUARIO";
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
var todos = PreenchePropriedade(reader);
lista.Add(todos);
}
}
return lista;
}
}
private Usuario PreenchePropriedade(OleDbDataReader reader)
{
var todos = new Usuario();
todos.Matricula = reader.GetString(0);
todos.Nome = reader.GetString(1);
if (!reader.IsDBNull(2))
{
todos.Acessos = Convert.ToInt32(reader.GetValue(2));
}
return todos;
}
}
The problem I’m having is that in my gridView it’s returning all attributes of a user entity that I have in my project. My question is how do I return only these 3 data in my gridView ??
private void ObterTotalPorMatricula()
{
var usuarioController = new UsuarioController();
var lista = usuarioController.ObterTotalporMatricula();
this.GridView1.DataSource = lista;
this.GridView1.DataBind();
gridVIew is returning the attributes of my User + Entity
public class Usuario : EntidadeBasica
{
public string Nome { get; set; }
public string Matricula { get; set; }
public string Senha { get; set; }
public int NivelAcessoId { get; set; }
public int ? CodigoMaleta { get; set; }
public string Email { get; set; }
public int Acessos { get; set; }
}