locked
csv file using CSVReader RRS feed

  • Question

  • i'm using CSVReader

    file as below
    no,item,salary
    1,A,3000.45
    2,B,4000.55
    3,A,3400.67
    4,B,3750.88
    5,B,3800.99

    but i could only get
    4000.55
    3500.67
    3750.88
    3800.99


    how to get the first column as well e.g.
    2,4000.55
    4,3750.88
    5, 3800.99

    private void button2_Click(object sender, EventArgs e)
            {
                using (CsvReader csv =
                       new CsvReader(new StreamReader(@"D:\input.txt"), true))
                {
                    int fieldCount = csv.FieldCount;
                    string[] headers = csv.GetFieldHeaders();
    
                    while (csv.ReadNextRecord())
                    {
                      
                        float abc= float.Parse(string.Format("{1}",headers[2], csv[2]));
                        if (abc> 3500)    
                        listBox1.Items.Add(abc);
                    }
                }
    
            }
    Wednesday, July 15, 2009 2:48 AM

Answers

  • listBox1.Items.Add(string.Format("{0}, {1}", csv[0], abc));
    • Marked as answer by tiau Wednesday, July 15, 2009 7:11 AM
    Wednesday, July 15, 2009 6:04 AM