0

Hey I am trying to do a project on Test Engine. I need to retrieve random rows of questions from access database. I did the following code, but every time I once close and run it again, the sequence of questions is same. How can I change the sequence every time?

private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection(Connection.conStr);
            OleDbCommand cmd = new OleDbCommand("select * from dell order by Rnd(serialNumber)", con);
            OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "new");
            dataGridView1.DataSource = ds.Tables["new"];
        }
4
Contributors
5
Replies
10
Views
5 Years
Discussion Span
Last Post by guru_iyer
Featured Replies
  • check [URL="http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/"]this link[/URL] it contains a detailed discussion on how to randomly select values Read More

0

Use any of these Queries

SELECT *, rand(@@IDLE % (@@ROWCOUNT + serialNumber))as xx FROM dell ORDER BY xx
//or
SELECT *,(sin(serialNumber * rand())) as xx from dell
ORDER BY xx

Edited by abelLazm: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.