0

我正在尝试制作一个程序,该程序将通过单击一个按钮来显示我的 ms 访问数据库中的随机数据。现在我有点迷路了..

这是我目前拥有的。你能帮我找到一种方法来随机显示数据库中的每行数据吗?

    {

        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();
   }
4

0 回答 0