我创建了多选系统,用户需要从4个radiobutton中选择答案,然后点击下一个按钮导航到下一个问题。
所以,我在选择的radiobutton存储到数据库时遇到了问题。首先,我创建一个表,我创建列来存储每个答案,但它失败了。现在,我被困住了。请提出我可以存储答案的任何建议。
这里我提供了加载问题的代码
p / s:我知道我应该在不同的主题上问这个问题,但我也坚持如何随机化放射线按钮。
Public Property Counter() As Integer
Get
Return IIf(ViewState("counter") Is Nothing, 1, CInt(ViewState("counter")))
End Get
Set(ByVal value As Integer
ViewState("counter") = value
End Set
End Property
Protected Sub Next_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Counter += 1
question()
clean()
End Sub
Sub question()
conn.Open()
Dim cmd As New SqlCommand("Select * From ques Where Id=@Id", conn)
cmd.Parameters.AddWithValue("@Id", Counter)
Dim dr1 As SqlDataReader
dr1 = cmd.ExecuteReader
If dr1.Read() Then
Me.lblquestion.Text = dr1("question")
Me.RadioButton1.Text = dr1("right")
Me.RadioButton2.Text = dr1("wrong")
Me.RadioButton3.Text = dr1("wrong2")
Me.RadioButton4.Text = dr1("wrong3")
Else
conn.Close()
Counter += 1
question()
End If
conn.Close()
End Sub
Sub clean()
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
Next.Enabled = False
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
question()
End Sub
Protected Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
Next.Enabled = True
End Sub
Protected Sub RadioButton2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
Next.Enabled = True
End Sub
Protected Sub RadioButton3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
Next.Enabled = True
End Sub
Protected Sub RadioButton4_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
Next.Enabled = True
End Sub
End Class
答案 0 :(得分:0)
我会有这样的数据库结构:
TblQuizes
Quiz_Id int
Quiz_Name nvarchar(200) -- or any other number that meets your demands
TblQuestions
Question_Id int
Question_Quiz_Id int --(FK To TblQuizes)
Question_Text nvarchar(200) -- or any other number that meets your demands
TblAnswers
Answer_Id int
Answer_Question_Id int --(FK To TblQuestions)
Answer_Text nvarchar(200) -- or any other number that meets your demands
Answer_IsCorrect bit
TblResults
Result_Id int
Result_Quiz_Id int -- (FK to TblQuizes) (not even needed, just to convenience)
-- Add user data in this table if you need it
TblResultDetails
ResultDetails_Id int
ResultDetails_Result_Id int --(FK to TblResults)
ResultDetails_Answer_Id int (FK to TblAnswers)
现在我要做的是为每个回答测验的用户在TblResults中创建一条新记录,并将用户答案存储在TblResultDetails中。 在这个基本结构上,您可以创建视图,为您提供向用户显示测验所需的全部数据,或向他展示他如何回答您的问题,等等。如果用户没有完成测验,只需比较TblQuetions和TblResultDetails中针对特定测验ID的记录数量,您也可以非常轻松地看到。
此外,如果您只想提出2个答案或6个答案的问题,则无需更改数据库结构或代码中的任何内容即可。