954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Multiple questions in a day

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:

private string GetCurrentQuestion()
        {
            string str = "";
            DataAccess da = new DataAccess();
            DataSet ds = new DataSet();
            da.Connect();
            ds = da.GetData("select * from questions where qdate = #" + DateTime.Now.ToString("dd-MMM-yyyy") + "#");
            if (ds.Tables[0].Rows.Count > 0)
            {
                str = "Question: " + ds.Tables[0].Rows[0]["ques"].ToString();
                str += "\nA." + ds.Tables[0].Rows[0]["ans1"].ToString();
                str += "\nB." + ds.Tables[0].Rows[0]["ans2"].ToString();
                str += "\nC." + ds.Tables[0].Rows[0]["ans3"].ToString();
                str += "\nD." + ds.Tables[0].Rows[0]["ans4"].ToString();
            }
            else
            {
                str = "Sorry! No Questions Today! Try again Tomorrow!";
            }
            da.Disconnect();
            return str;
        }
randr
Newbie Poster
5 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

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?

Murtan
Practically a Master Poster
671 posts since May 2008
Reputation Points: 344
Solved Threads: 116
 

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.

randr
Newbie Poster
5 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

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.

Murtan
Practically a Master Poster
671 posts since May 2008
Reputation Points: 344
Solved Threads: 116
 

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.

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

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.

hieuuk
Light Poster
44 posts since Nov 2008
Reputation Points: 11
Solved Threads: 4
 

Well with the questions per day thing you could dump their previous count each morning at midnight.

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

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.

randr
Newbie Poster
5 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Is time a reserved word? Could you name the column qtime like you did qdate?

Murtan
Practically a Master Poster
671 posts since May 2008
Reputation Points: 344
Solved Threads: 116
 
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.

randr
Newbie Poster
5 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

I was trying things in a test application.

DateTime.Now.ToString("HH:mm:ss") and DateTime.Now.ToString("hh:mm:ss tt")

both seem to produce valid output.

Does SQL like one format better than the other?

Murtan
Practically a Master Poster
671 posts since May 2008
Reputation Points: 344
Solved Threads: 116
 

I was trying things in a test application.

DateTime.Now.ToString("HH:mm:ss") and DateTime.Now.ToString("hh:mm:ss tt")

both seem to produce valid output.

Does SQL like one format better than the other?

Thanks it is solved.

randr
Newbie Poster
5 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You