I have a datatable with more that 10 column of different type.I need to change the type of columns. How to change the datatype of all datetime columns in a datable/dataset.
Asked
Active
Viewed 327 times
2 Answers
2
Try This
DataTable dtCloned = dt.Clone();
//change data type of column
dtCloned.Columns[0].DataType = typeof(Int32);
//import row to cloned datatable
foreach (DataRow row in dt.Rows)
{
dtCloned.ImportRow(row);
}
Or Check this out
Change DataType Of DataTable COlumn

Community
- 1
- 1

Amit Bisht
- 4,870
- 14
- 54
- 83
-
If you copy-paste code, add the source also! – Sriram Sakthivel Jan 03 '14 at 07:20
0
You can do this by following steps.
- Create new column with your new data types.
- Copy data from old column to new column. (but you remeber that data should compatible with new data type)
- Drop the old column.
- Rename the new column to old name. (use rename sp)
More details on this LINK.

Stuart
- 711
- 1
- 11
- 35