2
I am creating a program that stores the profiles of all teachers online currently in a list and then displays the first 3 in a label (where a button advances by displaying the next 3 online), but when I will assign the list values in a label it generates the following exception:
System.Argued tofrangeexception: 'The index was out of range. It should be non-negative and smaller than the collection size.'
Program code:
Consultar consultar = new Consultar();
SqlDataReader dr1 = null;
SqlDataReader dr2 = null;
List<string> nome = new List<string>();
List<byte[]> imagem = new List<byte[]>();
List<string> disciplina = new List<string>();
private int i = 0;
public ProfessoresOn()
{
InitializeComponent();
dr1 = consultar.PesquisaProfOnline();
while (dr1.Read())
{
nome.Add(dr1["NOME_PROFESSOR"].ToString());
imagem.Add(Encoding.ASCII.GetBytes(dr1["FOTO_PROFESSOR"].ToString()));
dr2 = consultar.PesquisaDisciplinaProf(dr1["IDPROFESSOR"].ToString());
while (dr2.Read())
{
disciplina.Add(dr2["NOME_DISCIPLINA"].ToString());
}
}
lblnome1.Content = nome[i];// O erro ocorre nesta linha
lblnome2.Content = nome[i++];
lblnome3.Content = nome[i+2];
ss can see where I went wrong agr. Thank you very much
– Gustavo