Click here to Skip to main content
14,640,713 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have this code:

string strConnection = ConfigurationManager.ConnectionStrings["SQLConnStr"].ConnectionString;
SqlConnection sqlcon = new SqlConnection(strConnection);
SqlCommand sqlCMD = new SqlCommand();
sqlCMD.Connection = sqlcon;
sqlCMD.CommandText = " ";
SqlDataAdapter sda = new SqlDataAdapter(sqlCMD);
DataTable dt = new DataTable();
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();


string connStrings1 = ConfigurationManager.ConnectionStrings["OracleConStr"].ConnectionString;
OracleConnection oclCon1 = new OracleConnection(connStrings1);
OracleCommand oclCMD1 = new OracleCommand();
oclCMD1.Connection = oclCon1;
oclCMD1.CommandText = " ";
OracleDataAdapter oda1 = new OracleDataAdapter();
oda1.SelectCommand = oclCMD1;
DataTable dt1 = new DataTable();
oda1.Fill(dt1);
GridView1.DataSource = dt1;
GridView1.DataBind();


What I have tried:

How can I merge them in one gridview in C#?
Posted
Updated 5-Jul-20 15:29pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Well, you don't indicate whether or not your tables/schemas are the same, but on the premise that they ARE the same,

1) Add your datatables dt, dt1 to a dataset

2) Bind your gridview to one of the datatables

3) In the SQL command used to select data, join dt, dt1 on a key

If your tables/schemas are different, 'merge' the dataables DataTable.Merge Method (System.Data) | Microsoft Docs[^] or you may wish to manually create a 3rd datatable and populate that using a SQL insert selecting and joining the data as required from the two 'base' datatables'
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100