D
dejavue82
I am trying to use a DataReader to read a table (that was attained from
JOINing two other tables) with the following format:
questions answers
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4
3 1
3 2
3 3
3 4
Unfortunately, I need to check both in the outer and inner loop to see
if reader.Read() == null.
At the same time, this statement not only checks to see if the reader
can go to the next row, but actually proceeds to the next row. It ends
up skipping the last answer of every question > 2. Any ideas? Thank you
for your time!
int quest_no = 0;
while (reader.Read())
{
quest_no++;
Label quest_count = new Label();
quest_count.Text = "Question " + quest_no.ToString() + ".
";
Label quest_lb = new Label();
quest_lb.Text = reader["quest"].ToString();
LabelPlaceHolder.Controls.Add(quest_count);
LabelPlaceHolder.Controls.Add(quest_lb);
CheckBoxList rad1 = new CheckBoxList();
while (((int)reader["quest_id"] == quest_no))
{
rad1.ID = quest_no.ToString();
rad1.Items.Add(reader["answ"].ToString());
LabelPlaceHolder.Controls.Add(rad1);
ArrayList possbAns = new ArrayList();
possbAns.Add(reader["is_true"]);
ViewState.Add(quest_no.ToString(), possbAns);
if (!reader.Read()) break;
}
}
LabelPlaceHolder.Controls.Add(new LiteralControl("<br>"));
}
JOINing two other tables) with the following format:
questions answers
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4
3 1
3 2
3 3
3 4
Unfortunately, I need to check both in the outer and inner loop to see
if reader.Read() == null.
At the same time, this statement not only checks to see if the reader
can go to the next row, but actually proceeds to the next row. It ends
up skipping the last answer of every question > 2. Any ideas? Thank you
for your time!
int quest_no = 0;
while (reader.Read())
{
quest_no++;
Label quest_count = new Label();
quest_count.Text = "Question " + quest_no.ToString() + ".
";
Label quest_lb = new Label();
quest_lb.Text = reader["quest"].ToString();
LabelPlaceHolder.Controls.Add(quest_count);
LabelPlaceHolder.Controls.Add(quest_lb);
CheckBoxList rad1 = new CheckBoxList();
while (((int)reader["quest_id"] == quest_no))
{
rad1.ID = quest_no.ToString();
rad1.Items.Add(reader["answ"].ToString());
LabelPlaceHolder.Controls.Add(rad1);
ArrayList possbAns = new ArrayList();
possbAns.Add(reader["is_true"]);
ViewState.Add(quest_no.ToString(), possbAns);
if (!reader.Read()) break;
}
}
LabelPlaceHolder.Controls.Add(new LiteralControl("<br>"));
}