Ajay Kadian

Ajay Kadian

  • NA
  • 122
  • 30.9k

how to access random data from database

Mar 18 2014 7:37 AM
Hi,
I have a MS access database. In that, one table consists of questions,option and answers.I need to retrieve random question from that table using Question Type but one by one it means at button click it shows one question on next click next question so on.
I have the code but it doesn't work.

And Please tell me it is possible to pass value One column value to textBox and 4 option column value to 4 button and if we click a button if its text value matches with answer(i.e in other column) then backcolor of button green else red.


cn.Open();
            OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\C#\\Database1.accdb");
            OleDbCommand cmd = new OleDbCommand("SELECT top 1 row Type from QUESTION ORDER BY rnd()", cn);
            
            OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp = new OleDbDataAdapter("Select * from QUESTION", cn);
            adp.Fill(ds, "QUESTION");
            dataGridView1.DataSource = ds.Tables["QUESTION"];
            cn.Close();


Answers (1)