title: How to extract columns and rows from a DataSet in ASP.NET C#
body: <p>*<strong><em>How can I compare the quantity of the UnitsInStock to the quantity the user wants to purchase?</em>*</strong></p>
  
  <p>Here I have a query to my SQL database for the list of columns put into a DataSet. The "where" clause is the item I am browsing currently, extracting all the current information about this product. </p>
  
  <p><strong>I tried to use get the data out into data columns, then I would now need to compare that with the int, quantity.</strong></p>
  
  <pre><code>        string selectionString =
          "SELECT Products.ProductID, " +
              "Products.ProductName, Categories.CategoryName, " +
              "Suppliers.CompanyName, Products.QuantityPerUnit," +
              "Products.UnitPrice, Products.UnitsInStock " +    
              "FROM Suppliers INNER JOIN (Categories  " +
              "INNER JOIN Products ON  " +
              "Categories.CategoryID = Products.CategoryID)  " +
              "ON Suppliers.SupplierID = Products.SupplierID " +
              "WHERE Products.ProductID = " +
              int.Parse(Session["Current Item"].ToString());
  
  DataSet ds = new DataSet();//this is the dataset that keeps my columns and rows.
  </code></pre>
  
  <p>Then I have a loop to assign all columns except for the last, which is UnitsInStock, towards text boxes. <strong>The value that I need to work with is an int, quantity.</strong></p>
  
  <p>Depending on the item that the user opens up, each item's stock will be different. So the item that I open up, I want to know how I can compare the variable quantity, decided by the user, to the quantity number that I have extracted from the DataSet.</p>
  
  <p>The index of the UnitsInStock column is <strong>6</strong>. Don't worry about QuantityPerUnit, it is nothing.</p>
  
  <p>Here is code that takes ProductName, CatergoryName, CompanyName, QuantityPerUnit, UnitPrice, and <em>UnitsInStock</em>, so you can see how the dataset is used. </p>
  
  <pre><code> if (ds.Tables[0].Columns.Count != 0 &amp;&amp;
          ds.Tables[0].Rows.Count != 0)
      {
  
          for (int index = 0; index &lt; ds.Tables[0].Columns.Count - 1; index++)/// count -1, explain
          {
              labelArray[index].Text = ds.Tables[0].Columns[index].ColumnName;//named constant
              if (index == 5) // The price field
              {
  
                  textBoxArray[index].Text = ((Decimal)ds.Tables[0].Rows[0][index]).ToString("F");
              }
              else
                  textBoxArray[index].Text = ds.Tables[0].Rows[0][index].ToString();
  </code></pre>
  
  <p>So, how can I compare the quantity retrieved by the database to the quantity the user wants to purchase, gathered from a textbox. </p>