Soul Reaver
Soul Reaver

Reputation: 2092

Converting datatype of column from string to double

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?

Upvotes: 0

Views: 2420

Answers (1)

Soul Reaver
Soul Reaver

Reputation: 2092

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 );

Upvotes: 1

Related Questions