title: .NET 2 DataTables in one single DataSet
body: <p>I got a Dataset that fills a gridview. The gridview has to be filled with one dataset and multiple queries (or datatables in this instance).</p>
  
  <p>As you can see in the code I used 2 DataTables. These Datatables are filled from a database (with sql server). The Datatables are added to one Dataset. In the ASP code you can see there are 3 labels and also 3 columns in the gridview. The first 2 columns are from the first datatable or the first query. The second query fills the last or third column.</p>
  
  <p>When I run this code it doesn't find <code>lblThree</code> in the dataset. <code>LblThree</code> is in the dataset but in the second table and .NET doesn't know that I guess. Do you guys know a solution for this error so I can fill my gridview with one dataset? </p>
  
  <pre><code>using System;
  using System.Collections;
  using System.Configuration;
  using System.Data;
  using System.Linq;
  using System.Web;
  using System.Web.Security;
  using System.Web.UI;
  using System.Web.UI.HtmlControls;
  using System.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;
  using System.Xml.Linq;
  using System.Data.SqlClient;
  
  namespace TwoDatatableToDataset
  {
      public partial class _Default : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
              if (!IsPostBack)
              {
                  loadAll();
              }
          }
  
          private void loadAll()
          {   // STEP ONE Put one sql output in an empty dataset: (works well)
              //DataSet ds = new DataSet();
              //DataTable dt2 = new DataTable();
              //string sql = "select SID1 as lblOne, Charge_Amount as lblTwo from [xxx].[xxxx].[xxxx]";
              //SqlConnection Scon = new SqlConnection(ConfigurationManager.ConnectionStrings["testserver"].ConnectionString);
              //SqlCommand Scmd = new SqlCommand(sql, Scon);
              //Scmd.CommandType = CommandType.Text;
              //SqlDataAdapter adp = new SqlDataAdapter(Scmd); // all data in adapter
              //Scon.Open();
              //adp.Fill(ds); //Adapter in dataset
              //GridView1.DataSource = ds; //dataset in gridview
              //GridView1.DataBind();
  
              //STEP TWO Make 2 datatables set them in one dataset
              DataSet ds = new DataSet();
              DataTable dt = new DataTable();
              DataTable dt2 = new DataTable();
  
              string sql = "select SID1 as lblOne, Charge_Amount as lblTwo from [xxxx].[xxxx].[xxxx]";            
              SqlConnection Scon = new SqlConnection(ConfigurationManager.ConnectionStrings["testserver"].ConnectionString);
              SqlCommand Scmd = new SqlCommand(sql, Scon);
              Scmd.CommandType = CommandType.Text;
              SqlDataAdapter adp = new SqlDataAdapter(Scmd); // all data in adapter
              Scon.Open();
              adp.Fill(dt); //Adapter in dataset
  
              sql = "select Currency as lblThree from [xxx].[dbo].[tbl_xx_NI]";            
              Scmd = new SqlCommand(sql, Scon);
              Scmd.CommandType = CommandType.Text;
              adp = new SqlDataAdapter(Scmd); // all data in adapter
              adp.Fill(dt2); //Adapter in dataset
  
              ds.Tables.Add(dt); //add data table to data set
              ds.Tables.Add(dt2);
  
              GridView1.DataSource = ds; //dataset in gridview
              GridView1.DataBind(); // ERROR: A field or property with the name 'lblThree' was not found on the selected data source.
  
              Scon.Close();
          }
      }
  }
  
  
  
  
  
      &lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TwoDatatableToDataset._Default" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;Untitled Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
                      &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                      AutoGenerateDeleteButton="False" AutoGenerateEditButton="False"&gt;
                       &lt;Columns&gt;
                          &lt;asp:BoundField DataField="lblOne" HeaderText="One" SortExpression="lblOne"&gt;
                              &lt;ItemStyle Width="20%"/&gt;
                          &lt;/asp:BoundField&gt;
                          &lt;asp:BoundField DataField="lblTwo" HeaderText="Two" SortExpression="lblTwo"&gt;
                              &lt;ItemStyle Width="20%" /&gt;
                          &lt;/asp:BoundField&gt;
                          &lt;asp:BoundField DataField="lblThree" HeaderText="Three" SortExpression="lblThree"&gt;
                              &lt;ItemStyle Width="20%" /&gt;
                          &lt;/asp:BoundField&gt;   
                       &lt;/Columns&gt;       
                  &lt;/asp:GridView&gt;    
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>