Thursday, June 14, 2007

Cast and Convert a column in dataview

For example you have an string column in dataview.
But the actual data in that column in numeric.
So you can not make calculations.
And you need to change the datatype of that column to int,decimal,etc...

There are several ways for converting a column datatype in a dataview.
The easiest way that I found:

DataTable dt = GetData_Bla_Bla();
DataView dv = dt.DefaultView;
dv.RowFilter = "CONVERT(COLUMN_NAME,'System.Decimal')>100";


I hope it works for you.

No comments: