TextFieldParser is always processing line 1

tech1guy
tech1guy used Ask the Experts™
on
Hi there,

I am processing a simple file using Microsoft.VisualBasic.FileIO.TextFieldParser, but it always process 1st row and remains in there and never comes out of while loop. What could be the problem?

ie. while(!textFieldParser.EndOfData) ....its never coming out of this loop.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Where is the rest of the code?...You should have ReadFields() inside your loop:

    string[] fields;
    while(!textFieldParser.EndOfData)
    {
        fields = textFieldParser.ReadFields();

        // ...use "fields" somehown...

    }
Most Valuable Expert 2012
Top Expert 2014
Commented:

Author

Commented:
my ReadFields method is within the while loop, but also within the if statement .... i.e I want to process the row IF the row starts with Orders........ otherwise I do not want to process the row......Is it possible to move the pointer the another row if the row is not Orders?
Most Valuable Expert 2012
Top Expert 2014

Commented:
ReadFields is what moves the pointer so you should call ReadFields whether you process the row or not. Use other ways of restricting the processing based on your condition.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Sure...that would look something like:

    string[] fields;
    while(!textFieldParser.EndOfData)
    {
        fields = textFieldParser.ReadFields();
        if (fields[0] == "Orders")
        {
            // process this row
        }
    }

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial