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

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

Post a Comment

Popular posts from this blog

How to make and use web service in Microsoft Dynamics Navision.

How to use Format function in Microsoft Dynamics Navision.

How to create simple report in Microsoft Dynamics Navision.