mohit1122:i want a value of 4 figures which is randomly generated by
Random RandomClass = new Random();
int RandomNumber = RandomClass.Next();
to be inserted into a table but avoiding duplication...
if the random value generated is already present in the table then i want it to calculate another value and so on until there is no duplication..
First of all, if you are going to limit it to 4 digits which means 0 - 9999 that is only 10,000 individual unique values so at some point you will clash.
If this is acceptable then the second question, is does the number have to be random or can it be sequential, that is you will get 1 2 3 4 5 ... and so on.
If it can be a sequential number then you can rely on the database to do this. Set up an integer column and enable the SEED with an increment on 1.
What this does is on each insertion the database will assign a incremented value of 1 from the previous value.
If it must not be sequential then you can continue using the Random class but you will need to check the database to see the integer is not used yet.