title: Properly disposing of variable. Are using statements enough?
body: <p>I have a class that contains methods that calls stored procedures. Some of these stored procedures return data structures others do not. Here is an example of one of the methods.</p>
  
  <pre><code>public DataTable GetProductData(int productID)
  {
    DataTable dataTable = new DataTable();
    using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
    {
      using (SqlConnection sqlConn = new SqlConnection("CONNECTIONSTRING"))
      {
        using (SqlCommand sqlCmd = new SqlCommand("getProductData", sqlConn))
        {
          sqlCmd.CommandType = CommandType.StoredProcedure;
          sqlCmd.Parameters.AddWithValue("@ID", productID);
          sqlConn.Open();
          sqlDataAdapter.Fill(dataTable);
        }
      }
    }
    return dataTable;
  }
  </code></pre>
  
  <p>This method is used by another program when data access is required. Here is an example of a method that makes use of the above method ...</p>
  
  <pre><code>public DataTable GetProductInfoFromDatabase(int productID)
  {
    DataLibrary dl = new DataLibrary();
    return dl.GetProductData(productID);
  }
  </code></pre>
  
  <p>What I am wondering is how I should dispose of the <code>dl</code> variable once I have retrieved the data. Will the garbage collection take care of it or should I implement IDisposable in the class where the <code>GetProductData</code> method is defined? Are the <code>using</code> statements enough?</p>