c# - Random Questions keep on repeating -


i have made system in visual studio using asp.net(c#) questions taken database , displayed users.

but questions getting repeated , can't figure whats wrong , plus questions not getting displayed.

below relevant c# code it

public partial class computertest : system.web.ui.page {     public static sqlconnection sqlconn;     protected string postbackstr;      protected void page_load(object sender, eventargs e)     {         sqlconnection con = new sqlconnection();         con.connectionstring = "data source=shahbaaz-pc;initial catalog=project;user id=sa;password=pass;";         postbackstr = page.clientscript.getpostbackeventreference(this, "time");         if (ispostback)         {             string eventarg = request["__eventargument"];             if (eventarg == "time")             {                 getnextquestion();             }         }     }     protected void button1_click(object sender, eventargs e)     {          label1.visible = false;         txtname.visible = false;         button1.visible = false;         panel1.visible = true;         lblname.text = "name : " + txtname.text;         int score = convert.toint32(txtscore.text);         lblscore.text = "score : " + convert.tostring(score);         session["counter"] = "1";         random rnd = new random();       int = rnd.next(1, 6);//here specify starting slno of question table , ending no.         //lblquestion.text = i.tostring();         getquestion(i);      }     protected void button2_click(object sender, eventargs e)     {         getnextquestion();      }     public void getquestion(int no)     {         sqlconnection con = new sqlconnection();         con.connectionstring = "data source=shahbaaz-pc;initial catalog=project;user id=sa;password=pass;";         string str = "select * computerquestion slno=" + no + "";         sqldataadapter da2 = new sqldataadapter(str, con);         dataset ds2 = new dataset();         da2.fill(ds2, "question");         if (ds2.tables[0].rows.count > 0)         {             datarow dtr;             int = 0;             while (i < ds2.tables[0].rows.count)             {                 dtr = ds2.tables[0].rows[i];                 session["answer"] = convert.tostring(convert.toint32(dtr["correct"].tostring()) - 1);                 lblquestion.text = "q." + session["counter"].tostring() + "  " + dtr["question"].tostring();                 rbloption.clearselection();                 rbloption.items.clear();                 rbloption.items.add(dtr["option1"].tostring());                 rbloption.items.add(dtr["option2"].tostring());                 rbloption.items.add(dtr["option3"].tostring());                 rbloption.items.add(dtr["option4"].tostring());                 i++;             }         }     }     public void getnextquestion()     {         if (convert.toint32(session["counter"].tostring()) < 6)//10 counter used 10 questions         {             if (rbloption.selectedindex >= 0)             {                 if (session["answer"].tostring() == rbloption.selectedindex.tostring())                 {                     int score = convert.toint32(txtscore.text) + 1;// 1 mark each question                     txtscore.text = score.tostring();                     lblscore.text = "score : " + convert.tostring(score);                 }             }              random rnd = new random();             int = rnd.next(1, 5);             //lblquestion.text = i.tostring();             getquestion(i);             session["counter"] = convert.tostring(convert.toint32(session["counter"].tostring()) + 1);          }         else         {             panel2.visible = true;          }     } 

any appreciated lot .

hi here problem random function. if want make sure 1 question repeated after questions have shown atleast one.

step 1: keep array length equal number of question.

step 2: random question .

step 3: check if id present in array.

        if not present           add   arrayand show questions         else         next random question repeat check 

step 3: before adding item array check

   if array full make array empty , add new question id 

repeat whole steps


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -