DataSet Problem

  • Thread starter Sparky Arbuckle
  • 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?
 
J

Jordan

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...
 
S

Sparky Arbuckle

When I run this SQL string in Access I always get at least 1 row
returned. This is due to my IIf function assigning '- ' if there is no
value in the first place. I added a rows count test to double-check
and make sure that my app didn't error out with 'There is no row at
Position 0.'
___________
Dim strSQL As String = "SELECT Max(IIf([Sheet.DCN] Is Null,'-
',[Sheet.DCN])) AS DCN, SheetType, SheetNumber FROM Sheet WHERE
(Sheet.Drawing = '" & x & "') AND (Sheet.SheetNumber = 0) GROUP BY
SheetNumber, SheetType;"


So the code below should assign strDCN a value of "- " if there are no
rows returned and if there is a row returned then strDCN equals the DCN
in that row.
___________
Dim strDCN As String

If ds.Tables("DataTable").Rows.Count < 0 Then
strDCN = "- "
Else
strDCN = ds.Tables("DataTable").Rows(0)("DCN")
End If

I am still getting "There is No Row at Position 0."
 

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

Similar Threads

Problem Returning a Dataset 0
How to bind a label to a dataset with C# 4
Problem with codewars. 5
Problem with KMKfw libraries 1
Java matrix problem 3
Dataset not Clearing 7
Dataset problem 0
Dataset - what!! 3

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,223
Latest member
Jurgen2087

Latest Threads

Top