Page

How to Generate random rows in dataset using c#.net

 SqlConnection con = new SqlConnection("Your Connection String");
            con.Open();

            string str = "select * from StudentDetail";
            SqlCommand cmd =new SqlCommand(str,con);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds =new DataSet();
            sda.Fill(ds);

            Random RandomNumber = new Random();
            int no = RandomNumber.Next(0,ds.Tables[0].Rows. Count);
            textBox1.Text = ds.Tables[0].Rows[no][0].ToString();

No comments:

Post a Comment