How to select random records from access 2007 database through c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sentimental37
    New Member
    • May 2010
    • 23

    How to select random records from access 2007 database through c#

    Hello everybody,
    I am developing a c# application in which i am using access2007 database. I want to select random records from the database through an access query in c#.but i am not able to do so.the format of my database is as:-
    tblQuestions-QuestionNo.Ques tion,Ans1,Ans2, Ans3,CorrectAns wer
    now i want to select random questionNo. and related fields and display them on my form.how to do this.plzzzzzz



    thanks
  • maddyromeo
    New Member
    • Jul 2010
    • 22

    #2
    since you have a questionnumber, , this might work

    Random rand = new Random();

    int i = rand.Next(int minquestionnumb er,int maxquestionnumb er); //generate random number

    DataSet ds=new DataSet();

    OleDbDataAdapte r da=new OleDbDataAdapte r("select questionno.ques tion,ans1,ans2, ans3 from table where questionno.ques tion like '"+i.ToString() +"%'",conn);
    //question with generated random number will be selected


    da.Fill(ds);


    same number may be generated twice , so you have to check it....

    Comment

    Working...