How to read a CSV file into a .NET Datatable
How can I load a CSV file into a System.Data.DataTable, creating the datatable based on the CSV file? Does the regular ADO.net functionality allow this? 22 Answers 22
How can I load a CSV file into a System.Data.DataTable, creating the datatable based on the CSV file? Does the regular ADO.net functionality allow this? 22 Answers 22
Currently, I’m using: DataTable dt = CreateDataTableInSomeWay(); List<DataRow> list = new List<DataRow>(); foreach (DataRow dr in dt.Rows) { list.Add(dr); } Is there a better/magic way? 28 Answers 28
DataSet and DataTable both implement IDisposable, so, by conventional best practices, I should call their Dispose() methods. However, from what I’ve read so far, DataSet and DataTable don’t actually have any unmanaged resources, so Dispose() doesn’t actually do much. Plus, I can’t just use using(DataSet myDataSet…) because DataSet has a collection of DataTables. So, to … Read more
How do create a DataTable in C#? I did like this: DataTable dt = new DataTable(); dt.clear(); dt.Columns.Add(“Name”); dt.Columns.Add(“Marks”); How do I see the structure of DataTable? Now I want to add ravi for Name and 500 for Marks. How can I do this? 13 Answers 13
I have few methods that returns different Generic Lists. Exists in .net any class static method or whatever to convert any list into a datatable? The only thing that i can imagine is use Reflection to do this. IF i have this: List<Whatever> whatever = new List<Whatever>(); (This next code doesn’t work of course, but … Read more
I’m trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example: var results = from myRow in myDataTable where results.Field(“RowNo”) == 1 select results; This is not allowed. How do I get something like this working? I’m amazed that … Read more