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
Solved

ado.net equivilant of recordset.MoveNext for DataSet

Posted on 2003-10-27
6
1,125 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
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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…

791 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