Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


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.
Posted
Updated 27-Oct-18 2:25am
v2
Comments
Alek Massey 24-Oct-18 10:31am    
Can you show the code you have tried?
BillWoodruff 24-Oct-18 12:51pm    
"i am able to copy entire table to new table, but dont know how to start this"

What exactly does "this" mean, here ? Describe the transformation, or re-ordering, you wish to perform: then we can help you

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);
    }
 
Share this answer
 
C#
datatable2 = datatable1.Copy();


it will copy all data of datatable1.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900