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:
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();
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();
This comment has been removed by the author.
ReplyDeleteThanks for this code. Could you please tell me how can i show data of two tables in a one cell. Please guide me.
ReplyDeletePlease tell me in detail, I have not understood. What you actually want ?
Delete