Datareader HasRows but don't read back or forward
In my previous post I submit this 'little' annoyance I have with Datareader.
Unfortunatly Matt and Dave your answer is wrong, I already tested with.Hasrows before, I should mention it in my post.
Hasrows is a valid test but don't read any data.
So if I write
If dtr.HasRows then
Poll_Question= dtr("Question")
End If
'-- Now bind to the radiobutton list
MyPoll.Datasource =dtr
MyPoll.Databind
I will still have an error.
The solution proposed by David is probably a good one.
If you are using stored procedures (which you should), then you could have the Question be an OUTPUT parameter. That way you don't have the question unnecessarily repeated in your resultset.
If you don't choose to go that path, then you could manually create the Items instead of setting the DataSource.
if (dtr.Read())
{
Poll_Question.Text = dtr["Question"].ToString();
MyPoll.Items.Add(...);
while (dtr.Read())
{
MyPoll.Items.Add(...);
}
}
dtr.Close();
And yes David I use SP all the time, but I was just thinking that for this small control, I could avoid them.
On the second part of your answer, you still miss the first record because of the dtr.Read.
How much I regret the good ASP Recordset.movenext and .moveprevious, .movelast, .movefirst !
Why this is not implemented in .Net ?
As I say before maybe the lack of a Datasource for some web controls like Label is the source of the problem.
Something I would like to investigate is that the Label control has a Databinding event, so maybe something to find there, who knows.