# Best way to search and find a number match in table[Answered] RSS

## 3 replies

Last post Jan 15, 2013 09:54 PM by Decker Dong - MSFT

• imchaz

Member

231 Points

357 Posts

### Best way to search and find a number match in table

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?

Member

602 Points

171 Posts

### Re: Best way to search and find a number match in table

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.

Good Luck
Do FEAR (Face Everything And Rise)
Please if my post helps you..!

• imchaz

Member

231 Points

357 Posts

### Re: Best way to search and find a number match in table

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.

• Decker Dong...

All-Star

94130 Points

18109 Posts

### Re: Best way to search and find a number match in table

Jan 15, 2013 09:54 PM|Decker Dong - MSFT|LINK

#### imchaz

imchaz

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(1000, 9999).Select(i => FIXNUMBER + i);
}
}```