C# 编辑数据表单元格

C# 编辑数据表单元格,c#,datatable,C#,Datatable,我想在我的数据表中编辑列中的单元格 DataTable theDataTable = new DataTable(); theDataTable.Columns.Add("Column1", typeof(string)); theDataTable.Columns.Add("Column2", typeof(string)); theDataTable.Columns.Add("Column3", typeof(string)); 它从一个文本文件中获取数据,看起来像这样 Column1

我想在我的数据表中编辑列中的单元格

DataTable theDataTable = new DataTable();
theDataTable.Columns.Add("Column1", typeof(string));
theDataTable.Columns.Add("Column2", typeof(string));
theDataTable.Columns.Add("Column3", typeof(string));
它从一个文本文件中获取数据,看起来像这样

Column1    Column2    Column3
2015-03-23 T_Someinfo 040-555555
2015-03-24 T_Someinfo 040-666666
2015-03-23 T_Someinfo 040-666666
现在我想在第3列中搜索“-”,并将其删除。 第3列中的结果如下所示

Column3
040555555
040666666
040666666

如何搜索“-”并将其从数据表的单元格中删除?

您可以尝试以下操作:

// We iterate through the DataTable rows.
foreach(DataRow row in theDataTable .Rows)
{
    // We get the value of Column3 for the current row and replace 
    // the - with empty.
    string value = row.Field<string>("Column3").Replace("-","");

    // Then we update the value.
    row.SetField("Column3", value);
}
//我们遍历DataTable行。
foreach(datatable.Rows中的DataRow行)
{
//我们得到当前行的Column3的值并替换
//房间里空荡荡的。
字符串值=行。字段(“Column3”)。替换(“-”,”);
//然后我们更新值。
行设置字段(“第3列”,值);
}

迭代抛出
并修改每个单元格,如:

foreach (DataRow row in theDataTable.Rows)
{
    if (row["Column3"] != null)
        row["Column3"] = row["Column3"].ToString().Replace("-", "");
}

遍历
并修改每个单元格,您尝试过什么吗?“它从文本文件中获取数据,看起来是这样的”然后更改从文本文件加载
数据表
的代码,而不是随后修复表。