In some cases, you may want to dynamically bind two datasets into a ASP.NET Datagrid. Here this article will brief you how you can achive the same
with the assistance of the Merging feature of the dataset.
string connectionString = "connection string";
SqlConnection sqlConnection = new SqlConnection(connectionString);
//Declare the Data Adapter here
SqlDataAdapter oAdapter1 = new SqlDataAdapter("select * from table1", sqlConnection);
SqlDataAdapter oAdapter2 = new SqlDataAdapter("select * from table2", sqlConnection);
//Declare the Datasets here
DataSet ds1 = new DataSet(); //Used to store table1 value
DataSet ds2 = new DataSet(); //Used to store table2 value
//Use the Data Adapter to fill the DataSet
oAdapter1.Fill(ds1);
oAdapter2.Fill(ds2);
dataSet1.Merge(ds2, False, MissingSchemaAction.Add);
//DataGrid1 - this is your datagrid
DataGrid1.DataSource=dataSet1;
DataGrid1.DataBind();
Here above the Merge method of the dataset, helps achieve this functionality.
As seen it takes three parameters:
The first parameter indicates the dataset to be merged with.
The second parameter indicates whether the changes need to be made to dataset or not
the final third argument specifies the MissingSchemaAction.