DataTable icon indicating copy to clipboard operation
DataTable copied to clipboard

How do I read row 0 when there are no headers?

Open CVertex opened this issue 10 years ago • 3 comments

I've got a bunch of CSVs with no header rows.

When I do

var dt = DataTable.New.ReadCsv("source-file.csv");
foreach (var row in dt.Rows)
{
    var idAsString = row.Values[0];

}

the first row is skipped. What's the best way to avoid skipping the first row if I know the CSV has no headers?

Thanks

CVertex avatar Oct 31 '15 03:10 CVertex

I haven't tried this but I am assuming that have you tried .... dt.GetRow(0) ???

amassaro avatar Nov 10 '15 00:11 amassaro

DataTable needs headers from somewhere. There are overloads of DataTable.New that let you pass in the headers. If you truly don't care about the names, you can pass in placeholder names ("c1", "c2", "c3"), but you should at least get the column count correct.

MikeStall avatar Nov 10 '15 00:11 MikeStall

@MikeStall , unfortunately DataTable doesn't have overload of DataTable.New with columns and delimiter specified both. Could you please add such?

arteny avatar Oct 23 '16 13:10 arteny