Solved

VB.Net - DataReader Looping

Posted on 2013-01-28
3
428 Views
Last Modified: 2013-01-29
Good Day Experts!

What is your preference to looping through a DataReader?  

I have seen:

While reader.Read()

End While

**************************

With reader
     .Read()
     Do While .HasRows

     Loop
End With

What are the pros/cons if any between the 2?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
[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
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 75 total points
ID: 38827179
I don't think there is any difference between the two approaches. Infact I suspect #2 will throw an error if there are no rows. I prefer the #1 approach.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 25 total points
ID: 38830185
CodeCruiser has it, there is not difference, but you should use the first set condition if you want to go the Loop route: Do While .Read().

There is something of a was between the proponents of the While and those who would rather use the Loop.

There is only one form of While...End While.

But there are 4 variations of the Do...Loop:
    Do While...Loop
    Do...Loop While
    Do Until...Loop
    Do...Loop Until

Those who prefer the Do...Loop argue that it gives you more control. I disagree with that. What I have seen in many years of code revision and debugging other programmers code is that those who use it often make mistakes. They think that they are in one form while they are in the other. This often end up missing one loop or doing one too many.

There is nothing that you can do with the Do...Loop that you cannot do with the While...End While. Just adjust the expression accordingly. But in my opinion, programmers who use the While...End While have only one way of seeing that kind of loop. They are used to it, and they do less mistakes.
0
 

Author Closing Comment

by:Jimbo99999
ID: 38831162
Thanks for the feedback as I continue my journey.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net Tranfer data between to VB.Net apps 8 44
Help with error in Query 2 39
get combo value in class 5 24
VB.net Duplicating a table - primary key not created 3 38
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

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