DataSet Problem

  • Thread starter Thread starter Sparky Arbuckle
  • Start date Start date
S

Sparky Arbuckle

Error: There is no row at Position 0.

This is the line that errors:

If ds.Tables("DataTable").Rows(0)("Rev") Is Nothing Then strRev = "New"

In my strSQL I have: "SELECT TOP 1 ItemName, (IIf([Rev] Is Null, 'New',
'[Rev]')) As Rev ... "

I thought that I have covered all of my bases. Any suggestions on why
it is that I'm receiving an error?
 
Your DataTable likely has zero rows.

Your code is attempting to look at the first row (row zero) - which doesn't
exist. The test for "Rev" being Nothing fails because there is no DataRow to
speak of, much less a column named "Rev" to evaluate for a possible value of
Nothing (or null). You are effectively telling your computer to "tell me if
a value is Nothing in a column in a row that doesn't exist." It's a
nonsensical question when you think about it.

You should add a test for Rows.Count... something like this:
If ds.Tables("DataTable").Rows.Count > 0 Then...
 

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