Solved

ado.net equivilant of recordset.MoveNext for DataSet

Posted on 2003-10-27
6
1,118 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with converting data format in xml file using VB.NET 11 54
Red error squiggly on vb.net 7 27
ADO.NET ENTITY DATA MODEL 3 32
Replace &lt; with < 14 57
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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

18 Experts available now in Live!

Get 1:1 Help Now