
Estou com problemas nas listagem, esse é meu codigo! alguem pode me ajudar?
public List<Anos> Listar()
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = Properties.Settings.Default.Configuração;
SqlCommand cn = new SqlCommand();
cn.CommandType = CommandType.Text;
con.Open();
cn.CommandText = "SELECT * from ano";
cn.Connection = con;
SqlDataReader dr;
List<Anos> lista = new List<Anos>();
dr = cn.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Anos dado = new Anos();
dado.Id_ano = Convert.ToInt32(dr["id_ano"]);
dado.Ano = Convert.ToInt32(dr["ano"]);
lista.Add(dado);
}
}
return lista;
}
}
