I was wondering how can i get n number of samples randomly from a local database using c#
What I have done so far.
"SELECT TOP "+n+" QUESTION,C1,C2,C3,C4,ANSWER FROM qPIPE WHERE CONTENT = 'Topic' ORDER BY RAND()"
"SELECT QUESTION,C1,C2,C3,C4,ANSWER FROM qPIPE WHERE CONTENT = 'Topic' ORDER BY RAND() LIMIT "+n+""
error: Additional information: Undefined function 'RAND' in expression.
"SELECT TOP "+n+" QUESTION,C1,C2,C3,C4,ANSWER FROM qPIPE WHERE CONTENT = 'Topic' ORDER BY NEWID()"
Additional information: Undefined function 'NEWID' in expression.
My connection string
ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0DataSource=|DataDirectory|\questionbank.accdb";
But when I try to query it to MS SQL
SELECT TOP n QUESTION, C1, C2, C3, C4, ANSWER FROM qPIPE WHERE CONTENT = 'Topic' ORDER BY NEWID()
It works fine. Get n number of questions from the table with the matching topic.
Im using MVS 2015, MSSMS 2017. Working on a win form.
edit:
edit:
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "SELECT TOP 2 QUESTION,C1,C2,C3,C4,ANSWER FROM qPIPE WHERE CONTENT = 'Thermodynamics' ORDER BY RND()";
OleDbDataAdapter dAdap = new OleDbDataAdapter(command);
DataTable dTable = new DataTable();
dAdap.Fill(dTable);
dataGridView1.DataSource = dTable;
connection.Close();