0

I am trying to make a program that will display a random data from my ms access database by clicking a button. And now i'm a bit of lost..

This is what i currently have. Can you help me find a way to display the datas from my database randomly each row?

    {

        OleDbConnection connection = new OleDbConnection();

        connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\miguel\Documents\QuotesGenFunny.accdb;
        Persist Security Info=False;";

        connection.Open();

        OleDbCommand command = new OleDbCommand();

        command.Connection = connection;
        command.CommandText = "SELECT Quote, Author FROM Funny";

        OleDbDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {

            lblQuote.Text = (reader["Quote"].ToString());
            lblAuthor.Text = ("-" + reader["Author"].ToString());
        }

        connection.Close();
   }
  • If you want to select a random row from a table you could add a Hash column to the table which will randomly sort each time and then select the top row. Is this what you are asking? Or apparently even better than my thought http://stackoverflow.com/a/19419/2145211 – Harrison Oct 14 '13 at 17:14
  • How large is this table? How often does it change? – Mike Perrenoud Oct 14 '13 at 17:14
  • @neoistheone I want to generate a single row every time i click a button with a random manner from my ms access database.. – user2572557 Oct 14 '13 at 17:30
  • @user2572557, I understand that much, but I was considering a cached solution if I could get my questions answered. – Mike Perrenoud Oct 14 '13 at 17:36
  • It would be better to load the data into the program if the table isn't large. Otherwise load the identifiers into the program and cycle through them. – Dustin Kingen Oct 14 '13 at 18:15

0 Answers0