- string CSVFilePathName = @"C:\test.csv";
- string[] Lines = File.ReadAllLines(CSVFilePathName);
- string[] Fields;
- Fields = Lines[0].Split(new char[] { ',' });
- int Cols = Fields.GetLength(0);
- DataTable dt = new DataTable();
-
- for (int i = 0; i < Cols; i++)
- dt.Columns.Add(Fields[i].ToLower(), typeof(string));
- DataRow Row;
- for (int i = 1; i < Lines.GetLength(0); i++)
- {
- Fields = Lines[i].Split(new char[] { ',' });
- Row = dt.NewRow();
- for (int f = 0; f < Cols; f++)
- Row[f] = Fields[f];
- dt.Rows.Add(Row);
- }
This is the code I have, which was working fine yesterday. However today without any changes made to the code it says:
System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
Any possible solutions?