Solved

ado.net equivilant of recordset.MoveNext for DataSet

Posted on 2003-10-27
6
1,115 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
  • 2
  • 2
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
Dexstar earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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
Comment Utility
Sorry for not closing sooner.
Daniel
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now