我正在尝试将更多值附加到DataTable的行中。从数据库读取的原始数据没有我想添加的另外两列。到目前为止我已经有了这个 -
myTable.Columns.Add("type", typeof(int));
myTable.Columns.Add("rate", typeof(int));
foreach (DataRow rows in myTable.Rows)
{
if (rows["dst"] == "1875")
{
//How to append values to this current row?
}
}
请建议。
答案 0 :(得分:1)
以下是答案
foreach (DataRow rows in myTable.Rows)
{
if (rows["dst"] == "1875")
{
//How to append values to this current row?
rows["type"] = 32;
rows["rate"] = 64;
}
}
同样作为最佳做法 - 将for循环中的行更改为行。它应该是单数的,因为它代表单个对象 - 而不是集合。