?
Solved

ado.net equivilant of recordset.MoveNext for DataSet

Posted on 2003-10-27
6
Medium Priority
?
1,136 Views
Last Modified: 2007-12-19
Hi
I can loop through all the rows in a dataset:
For each foo in bar.Dataset.Tables(0).Rows
  msgbox foo("id")
Next


I want to be able to step through and change rows, much like we can in vb6 with the RecordSet's MoveNext(), MoveFirst() etc methods.

I want to be able to do the following but in vb.net:

Do while not bar.Recordset.EOF()
    msgbox bar.recordset("id")
    bar.recordset.moveNext()
Loop



Thanks
Daniel
0
Comment
Question by:jasww
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
Dexstar earned 400 total points
ID: 9627925
jasww:

> I want to be able to step through and change rows, much like we can in vb6
> with the RecordSet's MoveNext(), MoveFirst() etc methods.

According to the Documentation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatarowcollectionmemberstopic.asp

There really aren't any MoveNext() or MoveFirst() methods.  The closest you can get to is this:
    Dim i As Integer
    For i = 0 To myTable.Rows.Count - 1
        Console.WriteLine(myTable.Rows(i)(0))
    Next i

Which isn't that different from the "For Each... Next" technique.

I guess the question is, why do you need to use EOF and MoveNext()?  Why won't For For Each...Next or For I = 0 To Count...Next work for you?  Maybe I can suggest a way to get the same result if I know what you're trying to do.

Hope that helps,
Dex*
0
 

Author Comment

by:jasww
ID: 9627975
Yeah, I've ended up using that method.
I want to be able to advance a globally scoped dataset from anywhere within the code.
Using the For Each method I am tied to this section of the code, meaning all processing has to occur within the For Each loop.
Not a big deal, I just wondered if there was a better way.

Do you think this is a step backwards for .net?  I do.  I liked MovenNext().

Daniel
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9627995
jasww:

> Do you think this is a step backwards for .net?  I do.  I liked MovenNext().

No, this is a step forward.  With the old style, the "current" record was a property of the recordset.  If you had 2 parts of your program trying to access 2 records at the same time, it will cause you grief because the first one will set the current record, and then the 2nd one will set the current record, and when the 1st part tries to read the data, it will read the record that the 2nd one set as current.  They conflict with each other.

With this technique, each part of the program can just get the record they want independently.  If you like MovenNext(), then you can just get the record that you want at any time with the Tables(0).Rows(n) command.

It is a little different, but you can still do whatever you need to do, and it is much more convenient for multithreaded applications.

Hope that helps,
Dex*
0
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 9628322
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10232132
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: Dexstar {http:#9627995} & TheLearnedOne {http:#9628322}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 

Author Comment

by:jasww
ID: 10234224
Sorry for not closing sooner.
Daniel
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question