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

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'
 
Share this answer
 

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