lower and upper limit problem

  • 12 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.



  • 12 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++)

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

  • 12 years ago

    Thanks a lot James. nice logic.

Post a reply

Enter your message below

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


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.

“XML is like violence - if it's not working for you, you're not using enough of it.”