私は新しい ASP.NET 開発者で、ASP.NET Web サイトで説明されているものと同様の単純なクイズ エンジン Web ベース アプリケーションを開発しました。アプリケーションは非常にシンプルで、多肢選択式の質問 (4 つの可能な回答のみ) のみが表示されます。単一回答または複数回答の多肢選択問題など、さまざまな種類の質問を表示するように改善する必要があります。現在、可能な選択肢 (2 つの選択肢または 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 つの選択肢) を含むあらゆる種類の質問を表示できるクエリを考え出す必要があります。
注: ASP.NET コードに示されているように、設計で QuizID を SessionParameter として使用する必要がありますか?