0
votes

I am triyng to Make a program which shows the user random english words(taken from an access DB) and requires him to write the hebrew defenition of the word. I managed to program this very easily using "cells(X,Y)" in excel VBA... But now when I am triyng to do it in c# and access I am getting a bit lost. I managed to get the reader working - the question is - how to tell it read only a specific row in my project? I.E. - it gets a random number of 5, and then it shows the value of the english word in row 5, and expects to recieve the hebrew word in row 5 as an answer.

this is what i currently achieved:

     private void button1_Click(object sender, EventArgs e)
            {
            string conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Words\WordsDatabase.accdb";
            string mySelect = "SELECT english,hebrew FROM study";
            OleDbConnection dbConnect = new OleDbConnection();
            dbConnect.ConnectionString = conStr;
            dbConnect.Open();
            OleDbCommand dbCmd = new OleDbCommand(mySelect, dbConnect);
            OleDbDataReader dbReader = dbCmd.ExecuteReader();

      while (dbReader.Read())
        {
        textBox1.Text +=  dbReader.GetValue(0).ToString() + "\r\n";
        textBox2.Text += dbReader.GetValue(1).ToString() + "\r\n";

        }


    }

Thanks a lot, Barak.

2

2 Answers

0
votes

The question is SQL related really. Change the mySelect to:

SELECT TOP 1 english, hebrew FROM study ORDER BY NEWID()
0
votes

The MS Access equivalent query would be:

SELECT TOP X english, hebrew FROM study ORDER BY Rnd(-10000000*TimeValue(Now())*[id])

Where

  • [id] is the numeric (autonumber most likely) primary key field for study
  • X is the number of rows you would like returned.

Credit