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();
        
 

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Thanks for this code. Could you please tell me how can i show data of two tables in a one cell. Please guide me.

    ReplyDelete
    Replies
    1. Please tell me in detail, I have not understood. What you actually want ?

      Delete

Thanks for comment

 
Toggle Footer