i am having some trouble trying to stock one row (Id) of my table (contas) to my array (ids[ ]), according to the requisites (posicao like 'Saúde', convenio like convenio and i can't have any duplicated Id's). The variables 'e' and 'i' are merely accountants. I'm kinda new to coding so please don't judge me hard. Also it's my first post on this site + I don't know english very well.
This is my code:
// Here I select the number of Id's that are compatible with my requisites, so far so ok
cmd = new SqlCommand("select COUNT(Id) from contas where posicao like 'Saúde' and convenio like '" +convenio+"'", con);
cmd.Parameters.AddWithValue("@Id", Id);
numeroidentista = (cmd.ExecuteScalar()).ToString();
// Here I create my arrays to store the data
int[] ids = new int[Convert.ToInt32(numeroidentista)];
string[] idst = new string[Convert.ToInt32(numeroidentista)];
string[] inst = new string[Convert.ToInt32(numeroidentista)];
// And here I tryied so hard and it doesn't even matter
while (e < Convert.ToInt32(numeroidentista))
{
SqlCommand cmdao = new SqlCommand(inst[i].ToString(), con);
inst[i] = "SELECT Id FROM contas where posicao like 'Saúde' and convenio like '" + convenio + "' and Id > '" + ids[i] + "'";
SqlDataReader reader = cmdao.ExecuteReader();
if (reader.Read())
{
while (i < Convert.ToInt32(numeroidentista))
{
idst[i] = reader["Id"].ToString();
ids[i] = Convert.ToInt32(idst[i]);
i++;
}
}
e++;
reader.Close();
}