Click here to Skip to main content
16,016,738 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want two merge the two columns of datatable to dataset and want bind to gridview.
i try in following two ways but it merge datable to dataset with different table.

C#
DataTable DtAudit = new DataTable("AUDIT");
DataSet ds = null;
ds.Tables[0].PrimaryKey = new DataColumn[] { ds.Tables[0].Columns["AR_Code"] };
            DtAudit.PrimaryKey = new DataColumn[] { DtAudit.Columns["AR_Code"] };
            DataSet dsNew = new DataSet();
            dsNew.Merge(ds);
            ds.Merge(DtAudit);


And the second way
C#
DataTable DtAudit = new DataTable("AUDIT");
DataSet ds = null;
foreach(Datacloumn dc in DtAudit)
{
ds.Tables[0].columns.Add(dc)
}
Posted
Comments
Prerak Patel 30-Aug-11 23:43pm    
Not clear. You can directly bind the data table to gridview. And what do you mean by merge? You are copying the same table columns to other.

1 solution

Not sure what you are asking, but try the Load method of the table and see if it is what you want. For example,
oTable1.Load(oTable2.CreateDataReader())
 
Share this answer
 
v2
Comments
Sudhir Kumar Srivastava lko 1-Sep-11 3:48am    
Can u please explain in detail of your question?
Andy Missico 1-Sep-11 4:00am    
I cannot because your question is vague. Read the help on the Load method to see if it will help you. I gave you the syntax to get you started on a different possible solution.

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