//这里的dt是原datatable,dtNew是创建的datatable
DataTable dtNew = dt.Clone();
dtNew.Clear();
//把到货状态这一列设置为string类型
dtNew.Columns["到货状态"].DataType = System.Type.GetType("System.String");
//按行导入值,把dt中的值导入到dtNew中
for (int i = 0; i < dt.Rows.Count; i++)
{
dtNew.ImportRow(dt.Rows[i]);
}
for (int i = 0; i < dtNew.Rows.Count; i++)
{
for (int j = 0; j < dtNew.Columns.Count; j++)
{
if (dtNew.Columns[j].ColumnName == "到货状态")
{
dtNew.Rows[i][j] = dtNew.Rows[i][j].ToString() switch
{
"1" => "未到货",
"2" => "部分到货",
"3" => "全部到货",
_ => dtNew.Rows[i][j],
};
}
}
}