lower and upper limit problem

  • 9 years ago

    I have a table with 3 columns as follows:

    lower   upper     id
    12       20      100
    100      150     200


    I want to select range of numbers based on lower and upper column.
    For example I want to display numbers between 12 to 20 or from 100 to 150.
    How to do it. thanks in advance.

     

     

  • 9 years ago

     Well, your first step will be to pull out the lower and upper column values... how you do this will depend on where your data is stored! Say for instance, this is in a database and you're using a DataReader...

    int lower = (int)dataReader["lower"];
    int upper = (int)dataReader["upper"]

    and then you can build up your list:

    List<int> values = new List<int>();
    for(int i = lower; i<=upper; i++)
       values.Add(i);

    your values list will now have all the numers you need? :)

  • 9 years ago

    Thanks a lot James. nice logic.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Linux is only free if your time has no value” - Jamie Zawinski