这是我的问题。我正在尝试使用我的数据表的全名字段,并将名称分为第一个和最后一个,然后将这些名称添加到我的数据表的正确位置。到目前为止,这是我的。如何将值添加到现有行的新数据表列中
DataTable DBTable = LoadMailingListContent(Location);
List<string> fullNames = DBTable.Rows.OfType<DataRow>().Select(dr => dr.Field<string>(columnName)).ToList();
DBTable.Columns.Remove(columnName);
DBTable.Columns.Add("First Name");
DBTable.Columns.Add("Last Name");
foreach (string fullname in fullNames)
{
var names = fullname.Split(' ');
string firstName = names[0];
string lastName = names[1];
//here is where I want to add the new name values into their new fields
}
能设置我的foreach循环内的计数器和依赖于该行的指数将名称添加回来?我需要关于如何将新的名字和姓氏值添加回我的新字段的帮助。
感谢
这看起来不错!我没有想过要这样做,因为它知道哪一行。谢谢你的帮助。一旦我开始工作,我会更新答案。 – Mitch
@Mitch不客气。事情比你想象的更简单:) –