Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I display exact number of Questions only
    text
    copied!<p>In <code>Question set</code> i am getting all questions with particular <code>(topicID,Marks)</code>. I am displaying Question <strong>randomly</strong> for <code>totqsn</code> i.e. total number of questions to display say 10 questions ,I am storing Count for number of questions of particular marks(1,2,3,4) in this int variables <code>mark1Qsn,mark2Qsn,mark3Qsn,mark4Qsn</code> respectively , using below code i am able to display Qustions from QuestionSet(say contains 34 qustions with (TopicID,marks)) for totqsn(say display 10 questions randomly from QuestionSet).My problem is How can i display total 10 Question in which 3 questions of 1 mark,3 questions of 2mark,1 question of 3marks,3 questions of 4 marks i.e. <code>totqsn(10 questions= 3 qsn_of_mark1 + 3 qsn_of_mark2 + 1 qsn_of_mark3 + 3 qsn_of_mark3)</code> </p> <pre><code>public partial class GroupExmStart : Form { DBHandling db = new DBHandling(); string GrpID = ""; string TopiID = ""; int totQsn = 0; int mark1qsn = 0; int mark2Qsn = 0; int mark3Qsn = 0; int mark4Qsn = 0; int tik = 0; string QuestionSet = ""; static Random _r = new Random(); string[] randomQsn = null; string[] QAndA = null; public GroupExmStart(string GroupName, string DurationID) { InitializeComponent(); totQsn = Convert.ToInt16(conf[0]); mark1qsn = Convert.ToInt16(conf[3]);//this variable contains number of question to be display of mark 1 mark2Qsn = Convert.ToInt16(conf[4]); mark3Qsn = Convert.ToInt16(conf[5]); mark4Qsn = Convert.ToInt16(conf[6]); QuestionSet = db.GetQuestions(TopiID, "1"); QuestionSet = QuestionSet + db.GetQuestions(TopiID, "2"); QuestionSet = QuestionSet + db.GetQuestions(TopiID, "3"); QuestionSet = QuestionSet + db.GetQuestions(TopiID, "4"); int z = Quiz(QuestionSet); foreach (string qa in QAndA.OrderBy(i =&gt; _random.Next())) { if (qa != null) if (qa.IndexOf('~') != -1) { randomQsn[count] = qa; count++; if (count == totQsn) break; } } int Quiz(string data) { string[] words = data.Split('$'); randomQsn = new string[totQsn + 1]; QAndA = new string[words.Length + 1]; for (int i = 0; i &lt; words.Length; i++) { QAndA[i] = words[i]; } return 0; } } } </code></pre> <p>GetQuestions method accessing from DBHandling class</p> <pre><code>public string GetQuestions(string TopicID, string Marks) { string data = ""; try { string sql = "select QID,Question,Opt1,Opt2,Opt3,Opt4,AnsOp,Marks from Questions where TopicID IN(" + TopicID + ") and Marks=" + Marks; cmd = new OleDbCommand(sql, acccon); rs = cmd.ExecuteReader(); while (rs.Read()) { data = data + rs[0].ToString() + "~" + rs[1].ToString() + "~" + rs[2].ToString() + "~" + rs[3].ToString() + "~" + rs[4].ToString() + "~" + rs[5].ToString() + "~" + rs[6].ToString() + "~" + rs[7].ToString() + "$"; } } catch (Exception err) { MessageBox.Show(err.Message.ToString()); } return data; } </code></pre> <p>Thanks in advance for any help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload