private DataTable UpdateDataTable(DataTable argDataTable)
{
DataTable dtResult = new DataTable();
//克隆表结构
dtResult = argDataTable.Clone();
foreach (DataColumn col in dtResult.Columns)
{
switch (col.ColumnName)
{
case "钢束编号":
col.DataType = typeof(int);
break;
case "X1":
col.DataType = typeof(float);
break;
case "Y1":
col.DataType = typeof(float);
break;
case "X2":
col.DataType = typeof(float);
break;
case "Y2":
col.DataType = typeof(float);
break;
case "半径":
col.DataType = typeof(float);
break;
case "钢束面积":
col.DataType = typeof(float);
break;
case "孔道面积":
col.DataType = typeof(float);
break;
case "根数":
col.DataType = typeof(int);
break;
default:break;
}
}
foreach (DataRow row in argDataTable.Rows)
{
DataRow rowNew = dtResult.NewRow();
rowNew["钢束编号"] = row["钢束编号"];
//修改记录值
rowNew["X1"] = row["X1"];
rowNew["Y1"] = row["Y1"];
rowNew["X2"] = row["X2"];
rowNew["半径"] = row["半径"];
rowNew["钢束面积"] = row["钢束面积"];
rowNew["孔道面积"] = row["孔道面积"];
rowNew["根数"] = row["根数"];
dtResult.Rows.Add(rowNew);
}
return dtResult;
}
原文地址:https://www.cnblogs.com/gilgamos/p/10115195.html