sharmila k

sharmila k

  • NA
  • 62
  • 51.5k

how to display random number in vb.net c# coding?

Aug 24 2012 4:12 AM
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);

Answers (5)