943,747 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 1770
  • C# RSS
You are currently viewing page 1 of this multi-page discussion thread
Dec 9th, 2008
0

Multiple questions in a day

Expand Post »
How do I display multiple questions per day? Also, I am using Visual Studio 2005 and am using a database to retrieve the data.

This is the sample code:

C# Syntax (Toggle Plain Text)
  1.  
  2. private string GetCurrentQuestion()
  3. {
  4. string str = "";
  5. DataAccess da = new DataAccess();
  6. DataSet ds = new DataSet();
  7. da.Connect();
  8. ds = da.GetData("select * from questions where qdate = #" + DateTime.Now.ToString("dd-MMM-yyyy") + "#");
  9. if (ds.Tables[0].Rows.Count > 0)
  10. {
  11. str = "Question: " + ds.Tables[0].Rows[0]["ques"].ToString();
  12. str += "\nA." + ds.Tables[0].Rows[0]["ans1"].ToString();
  13. str += "\nB." + ds.Tables[0].Rows[0]["ans2"].ToString();
  14. str += "\nC." + ds.Tables[0].Rows[0]["ans3"].ToString();
  15. str += "\nD." + ds.Tables[0].Rows[0]["ans4"].ToString();
  16. }
  17. else
  18. {
  19. str = "Sorry! No Questions Today! Try again Tomorrow!";
  20. }
  21. da.Disconnect();
  22. return str;
  23. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
randr is offline Offline
5 posts
since Dec 2008
Dec 9th, 2008
0

Re: Multiple questions in a day

The current implementation only looks at the first record returned and builds an output string with the question and answer options.

If there was more than one question matched, how would it work?

Should this return all of the questions delimited in some fashion?

Should it always return a list of questions, that might be empty?

Should you pass a question index into this method and keep calling it until it returns something indicating no more questions?

How would the user interact with it?
Would all of the questions for the day be on the same page, or would you want one page per question?
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Dec 10th, 2008
0

Re: Multiple questions in a day

Click to Expand / Collapse  Quote originally posted by Murtan ...
The current implementation only looks at the first record returned and builds an output string with the question and answer options.

If there was more than one question matched, how would it work?

Should this return all of the questions delimited in some fashion?

Should it always return a list of questions, that might be empty?

Should you pass a question index into this method and keep calling it until it returns something indicating no more questions?

How would the user interact with it?
Would all of the questions for the day be on the same page, or would you want one page per question?
Its simply to implement more than 1 question for a day. Its like a quiz application, allowing the user to choose several questions to be answered.

I am not sure how it would go, to put a sort of timing interval (eg. restrict 5 questions in 24 hours) into the coding but I am not sure on how to begin with.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
randr is offline Offline
5 posts
since Dec 2008
Dec 10th, 2008
0

Re: Multiple questions in a day

The current database search uses where qdate = #" + DateTime.Now.ToString("dd-MMM-yyyy") + "#" which limits the search to only find records for the given date.

You could extend that to have a 'morning', 'afternoon' and 'evening/night' questions using time...

The only other was to implement it would be to somehow get the information as to whether or not the current user has already seen a particular question. (Maybe you could keep a last date/question index for each user?)

If the last question date was today's date, then select the next index question (if any).

Note that the database would need to have a field to establish the order that questions would be presented during the day.

Also note that some entity must be populating the database with questions for future dates so that when the date arrives there is a question available. The entity would have to support adding more than one question for a given date, potentially including an order in which the questions were to be presented.

Now you put some effort into the problem if you want me to post any more, the "I just can't think of anything" is all worn out.
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Dec 10th, 2008
0

Re: Multiple questions in a day

To restrict questions to x per day, or hour or whatever means you would have to log someones efforts.. or you select x questions that may run in a day and then randomize.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 10th, 2008
0

Re: Multiple questions in a day

Well, I'm not so sure though. If this is just a random multiple question everyday then I would go with this design:

- We will show a label as question and a few Radiobox for answer.
- Select a random question which the last occured is more than a week or well, you decide it.
- A timer control, every second it go up, 1 point will be decrease from the total point.

Quick-And-Easy
DB
tblUser
All the information, their correct answer and total question they took.
tblQuestion
All the question and the last time it occured.

If you don't mind about how big your database is or how complex it is.
tblUser
--Well all the user information if neccesary
tblQuestion
--List of all questions
tblAnswers
--List of all answer
tblAnswersQuestion
--Link the answer table and question table
[B]tblResult[B]
--Store when the user answer the question, is that correct or not and how long it take him to answer that...

With this structure sure you could calculate the statistic easily. But I think it's over the top a bit.
Reputation Points: 11
Solved Threads: 4
Light Poster
hieuuk is offline Offline
44 posts
since Nov 2008
Dec 10th, 2008
0

Re: Multiple questions in a day

Well with the questions per day thing you could dump their previous count each morning at midnight.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 15th, 2008
0

Re: Multiple questions in a day

Click to Expand / Collapse  Quote originally posted by hieuuk ...
Well, I'm not so sure though. If this is just a random multiple question everyday then I would go with this design:

- We will show a label as question and a few Radiobox for answer.
- Select a random question which the last occured is more than a week or well, you decide it.
- A timer control, every second it go up, 1 point will be decrease from the total point.

Quick-And-Easy
DB
tblUser
All the information, their correct answer and total question they took.
tblQuestion
All the question and the last time it occured.

If you don't mind about how big your database is or how complex it is.
tblUser
--Well all the user information if neccesary
tblQuestion
--List of all questions
tblAnswers
--List of all answer
tblAnswersQuestion
--Link the answer table and question table
[B]tblResult[B]
--Store when the user answer the question, is that correct or not and how long it take him to answer that...

With this structure sure you could calculate the statistic easily. But I think it's over the top a bit.
Thanks for all the help guys, I've solved it with placing a new column named time in the database file.

I've actually added a DateTimePicker control and only allow the user to select the time so that the user can specify the timing of the question to be set on each day. However, its giving me a syntax error in the SQL insert into statement

sql = "insert into questions(qdate, ques, ans1, ans2, ans3, ans4, ans, prize, time) values('" +
dtpQues.Value.ToString("dd-MMM-yyyy") + "','" +
dtpTime.Value.ToString("hh:mm:ss tt") + "','" +
txtQues.Text + "','" +
txtAns1.Text + "','" +
txtAns2.Text + "','" +
txtAns3.Text + "','" +
txtAns4.Text + "','" +
right + "','" +
txtPrize.Text + "'" +
")";


I think the error lies in this:

dtpTime.Value.ToString("hh:mm:ss tt") + "','" +

It somehow complains about the format, but I have actually set the custom format to be hh:mm:ss tt.

Any ideas?
Thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
randr is offline Offline
5 posts
since Dec 2008
Dec 15th, 2008
0

Re: Multiple questions in a day

Is time a reserved word? Could you name the column qtime like you did qdate?
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Dec 15th, 2008
0

Re: Multiple questions in a day

Click to Expand / Collapse  Quote originally posted by Murtan ...
Is time a reserved word? Could you name the column qtime like you did qdate?
I do not think so, I have tried and its still the same. I think it might have something to do with the SQL statement because I tried following the same format to display the date and its giving me syntax error.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
randr is offline Offline
5 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: image dragging in win mobile
Next Thread in C# Forum Timeline: Read data from database using array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC