/// <summary>
/// 修改数据表DataTable某一列的类型和记录值(正确步骤:1.克隆表结构,2.修改列类型,3.修改记录值,4.返回希望的结果)
/// </summary>
/// <param name="argDataTable">数据表DataTable</param>
/// <returns>数据表DataTable</returns>
private DataTable UpdateDataTable(DataTable argDataTable)
{
DataTable dtResult = new DataTable();
//克隆表结构
dtResult = argDataTable.Clone();
foreach (DataColumn col in dtResult.Columns)
{
if (col.ColumnName == "age")
{
//修改列类型
col.DataType = typeof(String);
}
}
foreach (DataRow row in argDataTable.Rows)
{
DataRow rowNew = dtResult.NewRow();
rowNew["MemberId"] = row["MemberId"];
rowNew["NickName"] = row["NickName"];
//修改记录值
rowNew["age"] = row["age"] + "岁";
dtResult.Rows.Add(rowNew);
}
//返回希望的结果
return dtResult;
}