I have a very big csv file like this (more than 12K rows) ;
Comment, DateTime Name, Age, Class, Place, --> these are the header columns
Good, 03/10/2022, John, 12, 3, UK,
Bad, 12/10/2022, Tom, 15, 2, US
This is a generalized example which shows column names. But it will be more than this columns some times.
I am reading it as shown below
List<string> lines = File.ReadAllLines(System.IO.Path.ChangeExtension(FileNameWithPath, ".csv")).ToList();
I need a datatable from the above mentioned csv file but i DO NOT want Comment and Place columns in the datatable.
Can anybody show me how we can achieve this ?
Column datatypes :
DateTime --> typeof(datetime)
Name --> typeof(string)
Age --> typeof(double?)
Class --> typeof(int)
dt.Columns.Remove("colNameString")ordt.Columns.RemoveAt(colIndex). Or for only one forward pass, build the datatable manually. Since you are getting the info in asList<string>it seems like there is some data marshalling you are going to be doing in any case