Hi,
In a winform I have a textbox called userid and next to it is a button called auto generate. The thing is on clicking this button auto generate it should generate a random number and should also validate it against the database(for sample of 10 entries to make sure that no duplicate entries are present). The random number should be alphanumeric or numeric
Vimal KandasamyPosted Apr 25, 2009, 9:12 AM
String[] ar={"a","b","c","d","e","f","g","h","z","0","1","2","3","9"};{now userid have combined string of 10 randomly generated value.
sachi vasishtaPosted Apr 25, 2009, 8:56 AM
ok thanks vimal.
Combining the random numbers from an array means :declaring an array of type string and storing all alphabets and digits in it? could you please show me how to do that?
Vimal KandasamyPosted Apr 25, 2009, 8:36 AM
check out below link
http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=57332
in my answer,
in array, you add all alphabetic and numeric values
and get 10 random values from that and combine it.
and we cant get Random no for 10 digit.because it accepts upto 9 digit.if you need 10 digit then you can prefix a digit with the result.
sachi vasishtaPosted Apr 25, 2009, 7:52 AM
Vimal KandasamyPosted Apr 25, 2009, 6:43 AM
For Random no Generation
Random rnd = new Random();
int userid=rnd.Next(min no, max no);
if you need a 8 digit code as user id then
give min no-10000000
give max no-99999999
and for duplicate entry checking, i have an idea, but it may not best idea.
you just use a select statement.something like
select * from urtable where userid=generated no
if it return empty dataset i.e with 0 rows or null
then its not available.you can insert a new entry with this no
if it return a row then you generate another no and check it with database.