Check for Datasource content

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone tell me what operator I use to check if the datasource has any
content?

Thanks

Exception Details: System.InvalidCastException: Operator is not valid for
type 'SqlDataReader' and string "".

Source Error:
Line 62: Dim myReader As SqlDataReader = cmd.ExecuteReader()
Line 63: DGPages.DataSource = myReader
Line 64: If DGPages.DataSource <> "" Then
Line 65: DGPages.DataBind()
Line 66: Else
 
Source Error:
Line 62: Dim myReader As SqlDataReader = cmd.ExecuteReader()
Line 63: DGPages.DataSource = myReader
Line 64: If DGPages.DataSource <> "" Then
Line 65: DGPages.DataBind()
Line 66: Else

I think....just off the top of my head.... that I would do a.....

Line 66: if myReader.Read then
 
That doesn't really solve what I'm trying to do... I don't think! Here is the
code! I need to see if the reader has content and if not then write a
message...

Dim myReader As SqlDataReader = cmd.ExecuteReader()
DGPages.DataSource = myReader
While myReader.Read()
If
'Check reader has content
Then
DGPages.DataBind()
Else
lblNoContent.Visible = True
lblNoContent.Text = "There a currently no pages for' &
FindOffice()"
End If
End While
 
I need to see if the reader has content and if not then write a
message...

The code i posted:

...if myReader.Read then...

....actually tries to read data from the database.
If there is no data, the myReader.Read call returns a "false",
and if there _is_ data to read, it returns "true".

So this should work:

if myReader.Read then
myGrid.databind()
else
msgbox("There's no data to read!")
end if

Jeppe Jespersen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top