Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,
Is It possible datatable array?
If Yes,How to define?
How to append one datatable to another datatable?
Plz, Send code or link.

Thanks
Mahendra Kumar Das
Posted
Updated 1-Jun-11 23:00pm
v2

Look at the DataSet.Merge method[^] - it merges a specified DataSet or DataTable into the current DataSet or DataTable.
 
Share this answer
 
Comments
ambarishtv 2-Jun-11 4:59am    
+5
Abhinav S 2-Jun-11 5:03am    
Sorry I had kept this question open in a tab while typing the answer. Thus we have ended up providing the same link. My 5. You were first!
The DataTable has a merge[^] method that you can use.
 
Share this answer
 
Comments
ambarishtv 2-Jun-11 4:59am    
+5
Abhinav S 2-Jun-11 5:02am    
Thank you.
You Can try this.....


DataSet ds = new DataSet();
           DataTable tbl1 = new DataTable();
           ds.Tables.Add(tbl1);
           DataColumn col1 = new DataColumn("EmpID", Type.GetType("System.Int32"), "");
           col1.AutoIncrement = true;
           col1.AutoIncrementSeed = 1;
           DataColumn col2 = new DataColumn("Name", Type.GetType("System.String"), "");
           tbl1.Columns.Add(col1);
           tbl1.Columns.Add(col2);

           tbl1.PrimaryKey = new DataColumn[1] { col1 };

           DataRow rw1 = tbl1.NewRow();
           rw1["Name"] = "Manoj Savalia";
           tbl1.Rows.Add(rw1);

           DataRow rw2 = tbl1.NewRow();
           rw2["Name"] = "Savalia";
           tbl1.Rows.Add(rw2);
           ds.AcceptChanges();

           DataTable tbl2 = tbl1.Clone();
           DataColumn col3 = new DataColumn("Address", Type.GetType("System.String"), "");
           tbl2.Columns.Add(col3);

           DataRow rw3;
           rw3 = tbl2.NewRow();
           rw3["EmpID"] = 10;
           rw3["Name"] = "Test";
           rw3["Address"] = "Ahmedabad";
           tbl2.Rows.Add(rw3);

           ds.Merge(tbl2, false, MissingSchemaAction.Add);
 
Share this answer
 
v2
Comments
Dalek Dave 2-Jun-11 5:40am    
Edited for Code Block.

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