Dataset EOF question

  • Thread starter Thread starter Anthony Sullivan
  • Start date Start date
A

Anthony Sullivan

In classic ADO I was about to simply say:

If not [Recordset].EOF Then
' Do something with the data
End If

Now that I am working with the Dataset object I am finding it a little more
cumbersome to establish whether I have reached the end of my dataset, or if
I have retrieved any data at all. Currently I would do something like this.
I'm sure this is horribly flawed but it's the best I've come up with to this
point.

If [DataSet].tables(0).rows.count > 0 then
' Do something with the data
End If

Anyone know of a better way to do this?

Thanks!

Anthony Sullivan
 
Hi Anthony,

Anthony Sullivan said:
In classic ADO I was about to simply say:

If not [Recordset].EOF Then
' Do something with the data
End If

Now that I am working with the Dataset object I am finding it a little more
cumbersome to establish whether I have reached the end of my dataset, or if
I have retrieved any data at all. Currently I would do something like this.
I'm sure this is horribly flawed but it's the best I've come up with to this
point.

If [DataSet].tables(0).rows.count > 0 then
' Do something with the data
End If

Acutally is quite correct.
There are a lot of variatons how to get to table you want but always you
have to check the rows count.
Anyone know of a better way to do this?


Forgive me, but I don't see how this is more more complicated - direct
access to rows...
Take note, that DataSet is radically different than recordset.
Recordset would map to DataTable as they both represents a singe table.
 
You need to make the paradigm shift into binding. While there is nothing
with your test, the proper method is to bind and allow the Framework to make
some decisions. This will not get you away from all coding, but you should
not have to loop through like you did in classic ASP, at least not in most
cases.

There are times I run tests like so:

if(ds.Tables[0].Rows.Count > 0)
{
}

But, you can also loop

for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
}

In most instances, however, you see code more like:

MyControl.DataSource = ds.Tables["TableName"].DefaultView;

Depending on how you build your DataGrids, you may or may not have to put in
a further test.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Hi Anthony,

Amost
If [DataSet].tables(0).rows.count > 0 then
' Do something with the data
End If
Roughly typed here
\\\
dim i as integer = ds.tables(0).rows.count -1
dim a as string = ds.tables.ds.tables(0).rows(i)("myfield").tostring
///
is the last row.

I hope this helps,

Cor
 
Thanks everyone for your replies. Miha was the only one that truly
understood what I was looking for but you all make good points.

Gregory, I understand that the best scenario would be to bind but binding is
not always the best way to do something and in those situations I would need
to establish recordset validity. Basically what I was looking for is
confirmation that I was doing it correctly. While I've been programming in
Classic ASP/ADO/COM for over 5 years now, ASP.NET is new to me so I'm still
figuring things out.

Thanks Miha for your help, and you are correct. It isn't all that complex I
just kinda figured that a similar call such as EOF would be supplied. It's
really no more difficult or complex to do it this way.

Thanks again everyone!

Anthony Sullivan

Miha Markic said:
Hi Anthony,

Anthony Sullivan said:
In classic ADO I was about to simply say:

If not [Recordset].EOF Then
' Do something with the data
End If

Now that I am working with the Dataset object I am finding it a little more
cumbersome to establish whether I have reached the end of my dataset, or if
I have retrieved any data at all. Currently I would do something like this.
I'm sure this is horribly flawed but it's the best I've come up with to this
point.

If [DataSet].tables(0).rows.count > 0 then
' Do something with the data
End If

Acutally is quite correct.
There are a lot of variatons how to get to table you want but always you
have to check the rows count.
Anyone know of a better way to do this?


Forgive me, but I don't see how this is more more complicated - direct
access to rows...
Take note, that DataSet is radically different than recordset.
Recordset would map to DataTable as they both represents a singe table.
 
Hi Miha,

The answer of Anthony did make me curious,
Now that I am working with the Dataset object I am finding it a little more
cumbersome to establish whether I have reached the end of my dataset, or
if I have retrieved any data at all. Currently I would do something like
this. I'm sure this is horribly flawed but it's the best I've come up with to
this point.

If [DataSet].tables(0).rows.count > 0 then
' Do something with the data
End If

Acutally is quite correct.

This is totally incorrect it gives not the answer if you have reached the
end of the dataset, if gives an answer if there are records, but what is
the follow up after the then, it is an absolute useless statement.

Sorry,

But the answer from Anthony did make me curious if I had it that wrong.

Cor.
 
Oh, yes, you are correct.
His code is has records equivalent.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Cor said:
Hi Miha,

The answer of Anthony did make me curious,
Now that I am working with the Dataset object I am finding it a little more
cumbersome to establish whether I have reached the end of my dataset, or
if I have retrieved any data at all. Currently I would do something like
this. I'm sure this is horribly flawed but it's the best I've come up with to
this point.

If [DataSet].tables(0).rows.count > 0 then
' Do something with the data
End If

Acutally is quite correct.

This is totally incorrect it gives not the answer if you have reached the
end of the dataset, if gives an answer if there are records, but what is
the follow up after the then, it is an absolute useless statement.

Sorry,

But the answer from Anthony did make me curious if I had it that wrong.

Cor.
 
Back
Top