怎么修改datatable中某一列的值?
1个回答
展开全部
/// </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);}//返回希望的结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询