1、必须先克隆DataTable
2、列换类型
3、逐行往新DataTable赋值,并转换某列类型
如:
DataTable dt = diorg.Clone(); //必须先克隆,此时并不包含数据
dt.Columns[col].DataType = typeof(bool);
foreach (DataRow row in diorg.Rows)
{
DataRow rowNew = dt.NewRow();
for (int i = 0; i < dt.Columns.Count; i++)
{
if (i == col)
{
try
{
rowNew[i] = Convert.ToBoolean(row[i]);
}
catch { }
}
else
rowNew[i] = row[i];
}
dt.Rows.Add(rowNew);
}
return dt;