Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SqlConnection con = new SqlConnection(@"Data Source=ATTRES-3BC2A6\SQLEXPRESS;Initial Catalog=harsha;Integrated Security=True");
            SqlDataAdapter da = new SqlDataAdapter("select * from Exam )", con);
            da.Fill(ds, "Exam");
            dt = ds.Tables["Exam"];
            i = dt.Rows.Count;
            int k = 0;
            dr = dt.Rows[k];
            Label1.Text = dr[0].ToString();
            RadioButton1.Text = dr[1].ToString();
            RadioButton2.Text = dr[2].ToString();
            RadioButton3.Text = dr[3].ToString();
            RadioButton4.Text = dr[4].ToString();

            dr = dt.Rows[k + 1];
            Label2.Text = dr[0].ToString();
            RadioButton5.Text = dr[1].ToString();
            RadioButton6.Text = dr[2].ToString();
            RadioButton7.Text = dr[3].ToString();
            RadioButton8.Text = dr[4].ToString();

            dr = dt.Rows[k + 2];
            Label3.Text = dr[0].ToString();
            RadioButton9.Text = dr[1].ToString();
            RadioButton10.Text = dr[2].ToString();
            RadioButton11.Text = dr[3].ToString();
            RadioButton12.Text = dr[4].ToString();

            dr = dt.Rows[k + 3];
            Label4.Text = dr[0].ToString();
            RadioButton13.Text = dr[1].ToString();
            RadioButton14.Text = dr[2].ToString();
            RadioButton15.Text = dr[3].ToString();
            RadioButton16.Text = dr[4].ToString();
            
            dr = dt.Rows[k + 4];
            Label5.Text = dr[0].ToString();
            RadioButton17.Text = dr[1].ToString();
            RadioButton18.Text = dr[2].ToString();
            RadioButton19.Text = dr[3].ToString();
            RadioButton20.Text = dr[4].ToString();


So I have four questions and I have four questions in my database also.
Whenever I login different time I should get shuffled question.
Is this code part correct? Or should I make some changes in the query?
Please suggest me.
Posted
Updated 21-Nov-11 22:34pm
v2
Comments
Smithers-Jones 22-Nov-11 4:34am    
Added code-block.
Smithers-Jones 22-Nov-11 4:37am    
You asked a similar question just an hour ago: http://www.codeproject.com/Questions/287742/check-the-code-and-suggest-me-the-solution
Don't repost.

Try This:

Random randNum;
Random oRandom = New Random(System.DateTime.Now.Millisecond);
Int MaxQue;
MaxQue=50;
RandNum = oRandom.Next(0, MaxQue);


Here the RandNum can be your Question's ID.
And you can use it for selecting question from database.

-Thanks.
 
Share this answer
 
In button click event write the following code:

Before that create static int i=0; in the global declaration part;

{
SqlConnection con = new SqlConnection(@"Data Source=ATTRES-3BC2A6\SQLEXPRESS;Initial Catalog=harsha;Integrated Security=True");
                  SqlDataAdapter da = new SqlDataAdapter("select * from Exam )", con);
                  da.Fill(ds, "Exam");
                  dt = ds.Tables["Exam"];
                  i = dt.Rows.Count;
                  
                  dr = dt.Rows[i];
                  Label1.Text = dr[0].ToString();
                  RadioButton1.Text = dr[1].ToString();
                  RadioButton2.Text = dr[2].ToString();
                  RadioButton3.Text = dr[3].ToString();
                  RadioButton4.Text = dr[4].ToString();
i++;
}


For each click you will get a differnt question from your database.

Hope this is useful for you.
 
Share this answer
 
v2
Comments
Smithers-Jones 22-Nov-11 4:40am    
Added code-block.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900