I have this block of code that reads a text file [Tab delimited] and returns a data table. But the problem is that it treats the first line of the file or record as a header and displays the remaining lines as records, which subtract the number of records by -1, so now I want the code to read the entire contents of the file as records.
here is the code:
streamReader reader = new streamReader (filePath); string line = reader.readLine(); Datatable dt = new Datatable (); DataRow row; string[] value = line.Split('\t'); foreach(string dc in value) { dt.columns.add(New DataColumn(dc)); } while(!reader.endofStream) { value = reader.ReadLine().split('\t'); if (value.Length == dt.Columns.Count) { row = dt.NewRow(); row.ItemArray = value; dt.Rows.Add(row); } } return dt;
When i try to remove
foreach(string dc in value) { dt.columns.add(New DataColumn(dc)); }
and all the lines that depend on it, dt returns nothing.
how can i solve it?
source share