我是一名新的 ASP.NET 开发人员,我开发了一个简单的基于 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 个选择),那么该怎么做呢?
注意:我是否应该在我的设计中使用 QuizID 作为 SessionParameter,如 ASP.NET 代码所示?