我是一名新的ASP.NET开发人员,我开发了一个简单的Quiz Engine基于Web的应用程序,类似于ASP.NET网站中解释的应用程序。该应用程序非常简单,它只显示多项选择题(仅有4个可能的答案)。 我现在必须改进它以显示不同类型的问题,例如单一答案或多个答案的多项选择问题。我现在正在努力查询将显示问题及其可能的选择(两个选择或4或5个选择) 。我有以下数据库设计:
Questions Table: QuestionID, Question, QuestionOrder, AnswerExplanation
Answers Table: AnswerID, Answer
Quiz Table: QuizID, Title, Description
QuizContent Table: ID, QuizID, QuestionID, AnswerID, isCorrect
(isCorrect是一个引用该问题的正确答案的标志)
我的旧查询如下:
SELECT [QuestionID], [Question], [Answer1], [Answer2], [Answer3], [Answer4], [CorrectAnswer], [QuestionOrder]
FROM [Question]
WHERE ([QuizID] = @QuizID)
ORDER BY [QuestionOrder]
我的ASP.NET代码:
<asp:DetailsView ID="questionDetails" runat="server" Height="50px" Width="550px" AutoGenerateRows="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" CssClass="generaltext" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" CssClass="boldtext" Width="80px" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="Question" HeaderText="Question:" SortExpression="Question" />
<asp:BoundField DataField="Answer1" HeaderText="A:" SortExpression="Answer1" />
<asp:BoundField DataField="Answer2" HeaderText="B:" SortExpression="Answer2" />
<asp:BoundField DataField="Answer3" HeaderText="C:" SortExpression="Answer3" />
<asp:BoundField DataField="Answer4" HeaderText="D:" SortExpression="Answer4" />
</Fields>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" CssClass="generaltext" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT [QuestionID], [Question], [Answer1], [Answer2], [Answer3], [Answer4], [CorrectAnswer], [QuestionOrder] FROM [Question] WHERE ([QuizID] = @QuizID) ORDER BY [QuestionOrder]">
<SelectParameters>
<asp:SessionParameter SessionField="QuizID" Type="Int32" Name="QuizID" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
现在,我必须提出一个查询,可以显示任何类型的问题及其可能的答案或选择(2或4或6个选项),所以该怎么做? < / p>
注意:我的设计中是否应将QuizID作为SessionParameter,如ASP.NET代码所示?
答案 0 :(得分:0)
如果您尝试在单独的查询中解决问题,那么这是一项非常简单的任务。
像
这样的东西1) Select your columns from questionsTable order by questionOrder where quizId=@yourQuizId
2) Select your columns from answersTable order by answerOrder where questionId=@questionId
您现在需要做的是
使用一些数据控件(Gridview等)来映射所有问题
在第一个gridview&amp;中的模板字段中删除另一个gridview数据源
达明。