Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:59:04+00:00 2026-06-13T12:59:04+00:00

* How can I compare the quantity of the UnitsInStock to the quantity the

  • 0

*How can I compare the quantity of the UnitsInStock to the quantity the user wants to purchase?*

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.

I tried to use get the data out into data columns, then I would now need to compare that with the int, quantity.

        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.

Then I have a loop to assign all columns except for the last, which is UnitsInStock, towards text boxes. The value that I need to work with is an int, quantity.

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.

The index of the UnitsInStock column is 6. Don’t worry about QuantityPerUnit, it is nothing.

Here is code that takes ProductName, CatergoryName, CompanyName, QuantityPerUnit, UnitPrice, and UnitsInStock, so you can see how the dataset is used.

 if (ds.Tables[0].Columns.Count != 0 &&
        ds.Tables[0].Rows.Count != 0)
    {

        for (int index = 0; index < 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();

So, how can I compare the quantity retrieved by the database to the quantity the user wants to purchase, gathered from a textbox.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:59:05+00:00Added an answer on June 13, 2026 at 12:59 pm

    The easiest way to compare them in your existing code would be another if (index == statement in your for loop:

    if (index == 6)
    {
        int qtyUserWants = int.Parse(qtyUserWantsTextbox.Text);
        int qtyInStock = (int)ds.Tables[0].Rows[0][index];
    
        if (qtyUserWants >  qtyInStock)
        {
            // do something
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a query where I can compare all columns in a
is there a way l can compare two columns | fields in django like
I would like to know if there is anyway I can compare two columns
I have an IEnumerable, listOfOnes, and an IEnumerable, listOfTwos. Assuming that I can compare
How can I compare the items in two lists and create a new list
there are two databases to compare,but I can't connect one database directly. so I
I have planned to go for asp.net MVC4 web API. Any one can compare
I am working on a query so that I can compare a word read
Is there any tool that can compare the development database and the public database?
I was wondering if i can compare two intergers in my sql statement. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.