Resolved TextFieldParser is skipping odd lines in .csv file

Anonymous

Well-known member
Joined
Sep 29, 2020
Messages
84
Programming Experience
Beginner
Hello,

I am creating an application where I have to read from a .csv file. Here is the snapshot of my data -

ShelfMachine NameIdentification NumberItemExport StatusTax StatusDelay StatusExport IdTax IdDelay Id
2245​
A
542221​
1VrE2
0​
0​
2​
2342151​
645432,65444
544333​
2245​
A
532466​
2EV42
1​
3​
1​
78545​
90564
34375​
2334​
B
7543653​
TVy2s
4​
4​
3​
856754​
37432
9958​
53566​
T
385745​
Ydw4d
5​
2​
1​
73842​
43655NULL


My application has to check the following conditions for every row -

if Export Status > Tax Status and if Tax Id and Delay Id id not Null then add Tax Id and Delay Id contents to List A

if Export Status = Tax Status and if Tax Id and Delay Id id not Null then add Tax Id and Delay Id contents to List A

if Export Status < Tax Status and if Export Id and Delay Id id not Null then add Tax Id and Delay Id contents to List B

My code is

C#:
 private void ReadFile()
        {
            try
            {
                TextFieldParser parser = new TextFieldParser(textBox1.Text);


                parser.SetDelimiters(",");
                string[] fields;
                while (!parser.EndOfData)
                {
                    parser.ReadLine();
                    fields = parser.ReadFields();


                        if(Convert.ToInt32(fields[4])>Convert.ToInt32(fields[5]))
                        {
                          if(fields[8]!= "NULL")

                            ListA.Add(fields[8]);

                        if (fields[9] != "NULL")
                        
                            ListA.Add(fields[9]);
                        
                        }

                        if (((Convert.ToInt32(fields[4]) == 0) && (Convert.ToInt32(fields[5]) == 0)))
                        {
                            if (fields[8] != "NULL")

                                ListA.Add(fields[8]);

                            if (fields[9] != "NULL")
                            
                                ListA.Add(fields[9]);
                        }

                        else
                    {
                        if (fields[8] != "NULL")

                            ListA.Add(fields[8]);

                        if (fields[9] != "NULL")

                            ListA.Add(fields[9]);

                    }

                    if (Convert.ToInt32(fields[4])< Convert.ToInt32(fields[5]))
                        {
                            if (fields[7] != "NULL")
 
                                ListB.Add(fields[7]);

                            if (fields[9] != "NULL")
                            
                                ListB.Add(fields[9]);                           
                        }
                   }

                parser.Close();

            }
            catch(Exception ex)
            {

            }
        }

But this is only reading even lines in the file.
 
What are you doing at line 12 ?
 
Back
Top Bottom