Breaking News
Loading...
Tuesday, 23 July 2013

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

For generating the random rows from the data set first you have to generate the random numbae and this number is pass to the dataset
CODE:

 SqlConnection con = new SqlConnection("Data Source=NIRAV-PC;Initial Catalog=Student;Integrated Security=True");
            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();
        
 

1 comments:

Thanks for comment

 
Toggle Footer