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
sharmila kPosted Aug 25, 2012, 1:17 AM
Thank you for your reply.
rahul jaiswalPosted Aug 24, 2012, 8:48 AM
you can try this concepet ..
sharmila kPosted Aug 24, 2012, 8:41 AM
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.
sharmila kPosted Aug 24, 2012, 8:22 AM
Thank You for your reply.
Sukesh MarlaPosted Aug 24, 2012, 7:15 AM
You can random CustomerId using following uqery
Select top 1 CustoemrId from TblCustomer order by newId()
Check this is correct answer if it helped