0

I am reading csv file to DataTable with GenericParsing lib. It reads all data as strings and I don't see any way to tell GenericParserAdapter to treat read data as double (leaving first two columns which are date and time, all the rest contain only numeric values).

So leaving this part of code, is there an easy way to convert datatype of existing string column to double?

Soul Reaver
  • 2,012
  • 3
  • 37
  • 52
  • 1
    Kindly use another Datatable (recreate with same column but different datatype) and in foreach loop copy the rows to new Datatable. – Rahul Uttarkar Nov 04 '14 at 10:02

1 Answers1

1

Damn, I wasn't able to find this answer earlier. Found it here

DataTable dtc = dt.Clone();
for ( int i = 2; i < dtc.Columns.Count; ++i )
    dtc.Columns[ i ].DataType = typeof( double );
foreach ( DataRow row in dt.Rows )
    dtc.ImportRow( row );
Community
  • 1
  • 1
Soul Reaver
  • 2,012
  • 3
  • 37
  • 52