locked
cvs file RRS feed

  • Question

  • User1426473991 posted

    How do you read a cvs file?

    Sunday, September 29, 2013 11:02 PM

Answers

  • User839260933 posted

    Hi

    I think it is csv file and not cvs file if i'm not mistaken.

    You can do this quite easily in simple cases where the fields in each row in the CSV file are in the same order as the corresponding columns in the DataTable:
    
       public static void TransferCSVToTable(DataTable dt, string  filePath)
       {
           string[] csvRows = System.IO.File.ReadAllLines(filePath);
           string[] fields = null; 
           foreach(string csvRow in csvRows)
           {
              fields = csvRow.Split(',');
              DataRow row = dt.NewRow();
              row.ItemArray = fields;
              dt.Rows.Add(row);
           }
       }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 30, 2013 2:02 AM
  • User-488622176 posted

    You take the code from somebody who did it before you : http://kbcsv.codeplex.com/  ;-)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 30, 2013 6:49 AM

All replies

  • User839260933 posted

    Hi

    I think it is csv file and not cvs file if i'm not mistaken.

    You can do this quite easily in simple cases where the fields in each row in the CSV file are in the same order as the corresponding columns in the DataTable:
    
       public static void TransferCSVToTable(DataTable dt, string  filePath)
       {
           string[] csvRows = System.IO.File.ReadAllLines(filePath);
           string[] fields = null; 
           foreach(string csvRow in csvRows)
           {
              fields = csvRow.Split(',');
              DataRow row = dt.NewRow();
              row.ItemArray = fields;
              dt.Rows.Add(row);
           }
       }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 30, 2013 2:02 AM
  • User-488622176 posted

    You take the code from somebody who did it before you : http://kbcsv.codeplex.com/  ;-)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 30, 2013 6:49 AM