Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing for DataSet EOF

Status
Not open for further replies.

Duron

Technical User
Dec 13, 2004
15
DE
First of all, I'm still really confused on using all these things. Now there's DataSets, DataReaders, DataTables, DataRows, etc. Its a lot harder than using a Recordset in ADO in VB 6, where you could just go

Do Until rs.EOF
myVariable = rs![Field1]
Loop

So here is what I got:
Do Until ds1.WHAT DO I PUT HERE?????
strNameOne = (mds.Tables("Rank").Rows(intCount).Item(0))
If strNameOne = strNameOnetxt Then
MsgBox("Yes")
Else
MsgBox("Nope")
End If
intCount = intCount + 1

Loop


mds is a DataSet.

I could loop until the intCount is a certain number. For he reason that I will always want to get a maximum of 10 rows' data. BUT I will not always have 10 rows. I might only have 2, so I will get an error.

There is no EOF. for DataSets. I tried Do Until ds1.HasErrors. That doesn't work either.
 
Dim Row as DataRow

For Each Row in ds1.Rows
strNameOne = (mds.Tables("Rank").Rows(intCount).Item(0))
If strNameOne = strNameOnetxt Then
MessageBox.Show("Yes")
Else
MessageBox.Show("Nope")
End If
intCount = intCount + 1
Next

Datasets are a collection of datarows. Use this to create a For Each Next loop.

Help?

Craig
 
another way to simplify things a little would be to go

dim r as DataRow
for each r in ds1.Rows
strNameOne = r.Item(0)
If strNameOne = strNameOnetxt Then
MessageBox.Show("Yes")
Else
MessageBox.Show("Nope")
End If
next mike griffith
----------------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
 
Your Code:
Do Until ds1.WHAT DO I PUT HERE?????


Try This:
Do While ds1.Read


I use this for the DataReader and it works like a charm.
 
That is a datareader though Kris. Normally a variable starting with ds would be a dataset which doesn't support the .read method.

Duron the solution that Mike and Craig gave will work well if you are using a datareader. The solution that Kris here has posted will work with a datareader. The difference being that a dataset is a modeled view of the data return that is held in memory. You could think of it as a small database of the requested data.

I say this because it supports constraints relationships multiple tables, rows etc. With it you can manipulate and read the data. When you are finished send it back the the database and the database will be updated.

The datareader on the other hand is a stream of data coming from the database on your .read command. It is a fast one time, one way flow of data, from the database to you.

This is a fairly high level explaination but hopefully it will clear things up for you a bit. That'l do donkey, that'l do
[bravo]
 
Those were all extremely helpful resposes. The DataRow thing seems like it should work good. Thanks Craig, Mike, Kris and Zarcom.
 
I found out that I also have to first have

For each dataTable in dataSet
For each dataRow in dataTable

Next dataRow
Next dataTable
 
Hi,

I think what you are trying to do is indeed something for a DataReader. Microsoft designed the DataReader for looping trough records without having to load all of them at once.

Suppose you have your OldeDBConnection : conn opened.

Dim com As New OleDB.OleDBCommand
com.Connection = conn
com.CommandText = "SELECT * FROM Customer"

Dim dr As OleDB.OleDBDataReader = com.ExecuteReader()

Do While dr.Read
'You can access fields for a record like this :
Dim s As String
s = dr("Name")
Loop

dr.close

Greetz,
Jan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top