Chris is right, what you're doing is binding the datagrid repeatedly to the
datareader. For every row of the datareader you are calling the databind
method, thus constantly updating the grid. You don't have to ever call the
read method when you are binding directly to the datareader. If you're using
ASP.Net 1.1, There is already a HasRows property for the datareader that you
can check and avoid the other steps alltogether. Just check the hasrows
property of the datareader then bind if true. Just don't call the read
method before binding as that will read the first row.
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:14**********************************@microsof t.com...
Can someone please tell me what is wrong with the following code!
I have a record in the datareader but it isn't showing up and niether is
the
label... I presume there is a problem with this code!
Thanks
..CODE..
Dim myReader As SqlDataReader = cmd.ExecuteReader()
Dim hasRows As Boolean
hasRows = False
DGPages.DataSource = myReader
While myReader.Read()
hasRows = True
If hasRows = True Then
DGPages.DataBind()
ElseIf hasRows = False Then
lblNoContent.Visible = True
lblNoContent.Text = "There a currently no pages for"
End If
End While
myReader.Close()