Binding Multiple DataSets in single GridView

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Data;  
  4. using System.Data.SqlClient;  
  5. using System.Data.Sql;  
  6. using System.Web;  
  7. using System.Web.UI;  
  8. using System.Web.UI.WebControls;  
  9. using System.Configuration;  
  10.   
  11. public partial class _Default : System.Web.UI.Page  
  12. {  
  13.     SqlConnection con =new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);  
  14.     SqlCommand cmd;  
  15.     SqlDataAdapter sa;  
  16.       
  17.     protected void Page_Load(object sender, EventArgs e)  
  18.     {  
  19.           
  20.     }  
  21.     protected void Button1_Click(object sender, EventArgs e)  
  22.     {  
  23.         //Binding GridView  
  24.         Bind_Data_Grid();  
  25.     }  
  26.     protected void Bind_Data_Grid()  
  27.     {  
  28.         con.Open();  
  29.         cmd = new SqlCommand("select * from Credentials", con);  
  30.         sa = new SqlDataAdapter(cmd);  
  31.         DataSet ds1 = new DataSet();  
  32.         sa.Fill(ds1);  
  33.   
  34.         cmd = new SqlCommand("select * from tblLocation", con);  
  35.         sa = new SqlDataAdapter(cmd);  
  36.         DataSet ds2 = new DataSet();  
  37.         sa.Fill(ds2);  
  38.   
  39.         //Merge two DataSets  
  40.         ds1.Merge(ds2);  
  41.         DataGrid.DataSource = ds1.Tables[0].DefaultView;  
  42.         DataGrid.DataBind();  
  43.   
  44.         con.Close();  
  45.    
  46.     }  
  47. }