title: Populating one dataset overwrites another dataset result
body: <p>Its been 2-3 hours and I can't still understand why its happening. Need help.</p>
  
  <p>I am populating dataGridView using dataset. There are two tables master and detail. I am using two datasets to fetch both tables from datasets (Also I've implemented class to fetch from database so I just call that class's function which return dataset containing result and I assign that to my local datasets).</p>
  
  <p>Now what is happening is 1st I fetch detail table and check whether its null etc and if not I fetch second. Here the problem arises as soon second gets populated 1st one overwrites. I am so out of my mind now that I can't understand what is happening. here's my code:</p>
  
  <pre><code>private void txtInvNumber_TextChanged(object sender, EventArgs e)
      {
          if (txtInvNumber.Text != "")
          {
              try
              {
                  DataSet dsdetail = new DataSet();
                  DataTable dtdetail = new DataTable();
                  string query = "SELECT sell.ItemId 'Item ID',Item 'Item Name' ,sell.Quantity ,Status ,Credit_Limit 'Credit Limit',"
                  + "Total_amount 'Total Amount' ,Discount_Allowed 'Discount' ,Discounted_amount 'Discounted Amount' , "
                  + "Payable_Amount 'Payable Amount',Advance 'Advance Paid',Amount_Received 'Amount Received', Amount_Receivable 'Amount Receivable' "
                  + "FROM dbo.DSelling_Information sell  join Item_Infomation it on  sell.ItemId=it.Item_ID "
                  + "where InvoiceNum = '" + txtInvNumber.Text + "'";
  
                  string query_master = "select Sale_Orde_date 'Date', mp.Cust_ID,CUST_Name,Total_Quantity,Total_Amount,"
                  + "Amount_Received,Amount_Receivable,Report_Status from dbo.MSelling_Information mp join dbo.Customer_Information cs on mp.Cust_ID=cs.CUST_ID"
                  + " where Invoice_num = '" + txtInvNumber.Text + "'";
                  dsdetail = db.func_ds(query);
                  if (dsdetail != null &amp;&amp; dsdetail.Tables != null &amp;&amp; dsdetail.Tables[0].Rows.Count &gt; 0)
                  {
                      ds2 = db.func_ds(query_master); &lt;--here dsitem gets populated too.
                      if (ds2 != null &amp;&amp; ds2.Tables != null &amp;&amp; ds2.Tables[0].Rows.Count &gt; 0)
                      {
                          dtSellDate.Value = DateTime.ParseExact(ds2.Tables[0].Rows[0]["Date"].ToString(), "M/dd/yyyy", CultureInfo.InvariantCulture);
                          txtCustID.Text = ds2.Tables[0].Rows[0]["Cust_ID"].ToString();
                          txtCustomerName.Text = ds2.Tables[0].Rows[0]["CUST_Name"].ToString();
                          txtTotalQuantity.Text = ds2.Tables[0].Rows[0]["Total_Quantity"].ToString();
                          txtTotalAmount.Text = ds2.Tables[0].Rows[0]["Total_Amount"].ToString();
                          txtAmountRcvd.Text = ds2.Tables[0].Rows[0]["Amount_Received"].ToString();
                          txtAmountRcvble.Text = ds2.Tables[0].Rows[0]["Amount_Receivable"].ToString();
                          txtReportStatus.Text = ds2.Tables[0].Rows[0]["Report_Status"].ToString();
                          dataGridView1.AutoGenerateColumns = true;
                          dtdetail = dsdetail.Tables[0];
                          //dataGridView1.DataSource = db.func_ds(query).Tables[0]; // dataset
                          dataGridView1.DataSource = dtdetail;
  
                          isDgFill = true;
                      }
                  }
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.ToString());
              }
          }
          else
          {
              ds1.Clear();
              dataGridView1.DataSource = null;
              dataGridView1.Columns.Clear();
              isDgFill = false;
          }
      }
  </code></pre>
  
  <p>I tried using new keyword but no luck</p>
  
  <pre><code>    dataGridView1.DataSource = new DataTable("dtdetail");
  </code></pre>
  
  <p>also this:</p>
  
  <pre><code>    dataGridView1.DataSource = new DataSet("dsdetail").Tables[0];
  </code></pre>
  
  <p>Here is another problem:
  I tried direct function call on populating data:</p>
  
  <pre><code>    dataGridView1.DataSource = db.func_ds(query).Tables[0];
  </code></pre>
  
  <p>it worked but on cellclick i need to do multiple calculations which includes fetching data from database so whenever i fetch using dataset it just make datasource of datagridview null. </p>
  
  <p>I am using different names for each dataset but nothing is happening. Please if anyone can tell where I am wrong i'll be thankful to him\her a lot. </p>