Merge two dataset and bind to gridview.

Santosh0683
Posted by Santosh0683 under ASP.NET category on | Views : 6108
public partial class Merging : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindDatagrid();
}

}
public void bindDatagrid()
{
SqlConnection con;
sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["myconnection"].ToString());

SqlDataAdapter da1 = new SqlDataAdapter("select * from Emp", sqlConnection);
SqlDataAdapter da2 = new SqlDataAdapter("select * from Orders", sqlConnection);
DataSet ds1 = new DataSet();
DataSet ds2 = new DataSet();
da1.Fill(ds1, "Employees");
da2.Fill(ds2, "Employees");
dataSet1.Merge(ds2, false, MissingSchemaAction.Add);
//dataSet1.Merge(dataSet2);
GridView1.DataSource = ds1;
GridView1.DataBind();
}
}

Comments or Responses

Login to post response