Hi friend,
I want to display random number based customer Id.
I got the result random number but, i want result as that random number as customer Id.
This is My Coding
-------------------------
Class file coding
----------------
public int LuckyNo()
{
cmd = new SqlCommand("select count(CustomerId) from tbl_Card where LuckyPerson='1'", con);
id = Convert.ToString(cmd.ExecuteScalar());
if (id == "")
{
eid = 0;
}
else
{
eid = Convert.ToInt16(id);
}
return eid;
}
Form Load Coding
--------------------------
lblRandamNo.Text = Convert.ToString(obj.LuckyNo());
NoCustomer = Convert.ToInt32(lblRandamNo.Text);
Button Coding
--------------------
obj.MyReader("select CustomerId from tbl_Card where LuckyPerson='1'");
while (obj.dr.Read())
{
lblResult.Text = obj.dr["CustomerId"].ToString();
}
obj.dr.Close();
Id = Convert.ToInt32(lblResult.Text);
//-----------Randam Number------------//
Random rand = new Random((int)DateTime.Now.Ticks);
int numIterations = 0;
numIterations = rand.Next(NoCustomer);
txtLuckyNo.Text = Convert.ToString(numIterations);
Loading

Sukesh MarlaRank #461 · 5.4K reputationPosted Aug 24, 2012, 3:15 AM EDT
You can random CustomerId using following uqery
Select top 1 CustoemrId from TblCustomer order by newId()
Check this is correct answer if it helped
sharmila k57 reputationPosted Aug 24, 2012, 4:22 AM EDT
Thank You for your reply.
sharmila k57 reputationPosted Aug 24, 2012, 4:41 AM EDT
Thank You for your reply.
I got random number only to display but, i can't get that random number as customerId.
Please any one give solution.
rahul jaiswal166 reputationPosted Aug 24, 2012, 4:48 AM EDT
you can try this concepet ..
sharmila k57 reputationPosted Aug 24, 2012, 9:17 PM EDT
Thank you for your reply.