C#将行集复制到具有条件的循环中的新数据表 [英] C# copy set of rows to new datatable in loop with conditions
问题描述
我是C#的新手,在这里我试图先将行集复制到新数据表并做一些工作并复制第二集并做一些工作。
整个表格如下所示。
i am new to C#, here i am trying to copy set of rows first to new data table and do some work and copy the second set and do some work.
the entire table looks like this.
Tables Concept1 Concept2
Name1 Th1 AA1
Th2 AA2
Th3 AA3
Th4 AA4
Name2 Tl1 BB1
Tl2 BB2
Tl3 BB3
Tl4 BB4
Tl5 BB5
这里的表格,Concept1和Concept2是标题。
所以我必须先复制Name1及其值并做一些工作然后再进行Name2和它的价值观并做一些工作。 (Name1和Name2不是静态的,可能会有所不同)
我的尝试:
i能够将整个表复制到新表中,但不知道如何开始这个:(。
请帮忙。
Here Tables, Concept1 and Concept2 are the headers.
so i have to copy the Name1 and its values first and do some work and next Name2 and its values and do some work. (Name1 and Name2 are not static it may vary)
What I have tried:
i am able to copy entire table to new table, but dont know how to start this :(.
Please help.
推荐答案
你好
如果你的意思是这个数据是在数据表中所以试试这个
Hello
If you mean this data is in datatable so try this
List<string> iListOfTables = new List<string>();
foreach (DataRow DRow in ExistingTable.Rows) {
if (!iListOfTables.Contains(DRow("TABLES"))) {
iListOfTables.Add(DRow("TABLES"));
}
}
DataTable NewTable = new DataTable();
foreach (string iTable in iListOfTables)
{
DataRow[] iRows = ExistingTable.Select("TABLES = '" + iTable + "'");
NewTable.Rows.Add(iRows);
}
datatable2 = datatable1.Copy();
它将复制所有da ta datata1。
it will copy all data of datatable1.
这篇关于C#将行集复制到具有条件的循环中的新数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!