Solved

quiz query

Posted on 2009-07-08
7
514 Views
Last Modified: 2012-05-07
please check and help me to get out
I have a task where i have to create a contest page 
 

i have already created a table called tblcontest 
 

tblcontest have contestid which is a primary key 
 
 

2) i have tblquestion where iam storing the questions and these questions will be related to contest id
 

hence in tblquestion i have created primary key as questionid and foreignkey as contestid
 

3) i have tblanswers which is storing 4 choice answers related to question id 
 

in tblanswers i have answerid as primary key and foreignkey as question id
 

4) the tblquestionanswers is having the questionid and answerid 
 

the question id is a question and answerid is a answer to the question
 
 

Now in asp.net page iam unable to call three questions with their multiple choice questions
 

i mean to say the quiz will have 3 question with multiple choice answers
 

each question will have 4 answers
 

below to this question i have also user info to store 
 

so i have created a tbluser with userid as a primary key
 

now, please help me how to fetch the data in asp.net page where i should be able to display  3 questions with 4 choice answers to each question
 

also the moment user submit the answers by clicking the submit button it shld store the user info as well as his answers history and later i should be able to see who is the winner or loser three correct quesion answers will make him winner

Open in new window

0
Comment
Question by:muneerz
  • 4
  • 2
7 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 24806768
First, let's cleanup the table design.  Specifications 3 and 4 are conflicting.  

Specification 3 implies: an answer belongs to a single question
Specification 4 implies: an answer may belong to many questions

In other words,  you have two ways to find the answers to a question.  One is to join tblAnswer to tblQuestion.  The other is to join tblQuestionAnswer to tblQuestion.  

So...it's not clear to me why you have tblQuestionAnswers in your design. In fact, if you ALWAYS, ALWAYS, ALWAYS have exactly 4 Answers to EVERY question, it is not clear to me why you have tblAnswers in your design.  (Although, the two absolutes in that assertion do cast come reservations).

Really, I'd suggest this design:

tblContest
  ContestID   (PK)

tblQuestion
   QuestionID (PK)

tblContestQuestion   (allows same question to be used in multiple contests)
   ConstestID (PK, FK)
   QuestionID (PK, FK)

tblAnswer
   QuestionID (PK,FK)  
   AnswerID  (PK)




 







 

0
 
LVL 42

Expert Comment

by:dqmq
ID: 24806787
Didn't quite finish.

I'd also have:

tblCorrectAnswer
   QuestionID (PK,FK)
   AnswerID (FK)
0
 

Author Comment

by:muneerz
ID: 24811245
I have created a database on my design and it is correct upto my knowledge, only the part along wuth userid how can i store the user details with correct answers,i want that code in asp.net code
0
[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

 
LVL 42

Expert Comment

by:dqmq
ID: 24824547
Like always, there are many ways.  But I would create a stored procedure to perform the insert and then invoke it from an ado command object, passing the questionID, UserI, and AnswerID as parameters.  You can find many examples on the web for how to call a stored procedure from VB or C# code behind an asp form.

0
 

Author Comment

by:muneerz
ID: 24829271
dear dg mg iam not able to find the solution in web, hence i have written to this forumn expecting a code help , please check you could help me in coding part
0
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 24946248
OK, here's some sample code to get you started
CREATE PROCEDURE [dbo].[InsertUserAnswer]

      @UserId integer,

      @QuestionId integer,

      @AnswerId integer, 

      @ContestId integer 

AS 

BEGIN 

      SET NOCOUNT ON; 

      INSERT INTO  tblUserAnswer (UserId, QuestionId, AnswerId, ContestId) 

      VALUES (@UserId, @QuestionId, @AnswerId, @ContestId) 

END 
 
 

---------------------
 

Dim strConnString As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString 

Dim con As New SqlConnection(strConnString) 

Dim cmd As New SqlCommand() 

cmd.CommandType = CommandType.StoredProcedure 

cmd.CommandText = "InsertUserAnswer"

cmd.Parameters.Add("@UserID,SqllDbType.Integer).Value = ????cmd.Parameters.Add("@QuestionID,SqllDbType.Integer).Value = ????

cmd.Parameters.Add("@AnswerID,SqllDbType.Integer).Value = ????

cmd.Parameters.Add("@ContestID,SqllDbType.Integer).Value = ????
 

cmdcmd.Connection = con 

Try 

      con.Open() 

      cmd.ExecuteNonQuery() 
 

Catch ex As Exception 

      Throw ex 

Finally 

      con.Close() 

      con.Dispose() 

End Try 

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL query to summarize items per month 5 53
Code works but I need to redo it and assign values to Model 7 33
Run time Error 4 34
Help with C#, MVC, razor. 6 23
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now