locked
Best way to search and find a number match in table RRS feed

  • Question

  • User-1071952197 posted

    I am having a user enter a block of telephone numbers into two textboxes.  The first box will be the full 10 digit number.  The second box will contain the last 4 numbers of a block sequence that is greater than the last 4 numbers of the first box sequence. I will validate to make sure its in a valid sequence.

    Box 1: 2171231000
    Box 2: 1005

    So basically the block of numbers to be added into by table are 6 numbers

    2171231000
    2171231001
    2171231002
    2171231003
    2171231004
    2171231005

    So basically, I have a stored procedure that checks to see if any of these numbers are already inputted into my table of BLOCK TELEPHONE NUMBERS.  If so, prompt the user that the first matched telephone number in the list is already entered and the block of sequence is terminated and the block of numbers as group is not entered into the table.

    So my code logic looks like this:

    For i as long = 2171231000 to  2171231005

    Use stored procedure and if it returns a FLAG ID of 1, the FLAG ID of 1 indicates a match is found.
    Message warning prompts USER of the found number and operation terminates.

    NEXT

    If it passes through the sequence successfully, then I add the block sequence into by table.
    RefID, FirstNumberBlock, LastNumberBlock
    5067, 2171231000, 2171231005

    I know this isnt the cleanest or best way to do this and this is where I am open for suggestions on how to improve this operation.
    In my example above if I had a USER input

    Box 1: 2171230000
    Box 2: 9999

    It would call my stored procedure 1001 and be very time consuming.

    Thoughts on how to change this?

    Monday, January 14, 2013 12:24 PM

Answers

  • User3866881 posted

    Hi,

    You can make your first some number characters "fixed", with the following ones after is created by Enumerable.Range (since 3.5). Here's the demo for you:

    class Program
        {
            const string FIXNUMBER = "217123";
            static void Main(string[] args)
            {
                var result = Enumerable.Range(10009999).Select(i => FIXNUMBER + i);
            }
        }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 15, 2013 9:54 PM

All replies

  • User226262986 posted

    hi

    you can use arrayList, first insert those number in list andthe using foreach loop send it to sotred procedure and remaining thing as you do if all available in the db then none will inserted else inserted if inserted the work as you before.

    Tuesday, January 15, 2013 8:49 AM
  • User-1071952197 posted

    hi

    you can use arrayList, first insert those number in list andthe using foreach loop send it to sotred procedure and remaining thing as you do if all available in the db then none will inserted else inserted if inserted the work as you before.

    In essence, that is what I am doing.  I am sending each number in the loop to a stored procedure and checking if that number exists in the database table.   But I think it would be ineffecient sending lets say 1000 numbers through a stored procedure.  I think there should be a better way.  Any other thoughts?  Thanks for your reply.

    Tuesday, January 15, 2013 9:23 AM
  • User3866881 posted

    Hi,

    You can make your first some number characters "fixed", with the following ones after is created by Enumerable.Range (since 3.5). Here's the demo for you:

    class Program
        {
            const string FIXNUMBER = "217123";
            static void Main(string[] args)
            {
                var result = Enumerable.Range(10009999).Select(i => FIXNUMBER + i);
            }
        }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 15, 2013 9:54 PM