Mysql 系统如何识别问题是否已得到回答

Mysql 系统如何识别问题是否已得到回答,mysql,vb.net,loops,xampp,system,Mysql,Vb.net,Loops,Xampp,System,我想知道系统如何识别问题是否已经得到回答,如果用户想回到上一个问题中。如果已经回答,则答案将更新,分数是否增加,或者如果答案未编辑,则答案将相同 按钮1是返回到上一个问题 按钮2用于检查应答器是否正确 按钮3用于继续进行考试 以下是我的代码片段: 导入MySql.Data.MySqlClient 导入系统。绘图 导入System.IO 公开课考试 '为连接声明变量' 将分数设置为整数 暗右翼为弦 Dim正确为整数=0 像字符串一样的模糊选择 作为字符串的Dim选项1 作为字符串的Dim choi

我想知道系统如何识别问题是否已经得到回答,如果用户想回到上一个问题中。如果已经回答,则答案将更新,分数是否增加,或者如果答案未编辑,则答案将相同

按钮1是返回到上一个问题 按钮2用于检查应答器是否正确 按钮3用于继续进行考试

以下是我的代码片段:
导入MySql.Data.MySqlClient
导入系统。绘图
导入System.IO
公开课考试
'为连接声明变量'
将分数设置为整数
暗右翼为弦
Dim正确为整数=0
像字符串一样的模糊选择
作为字符串的Dim选项1
作为字符串的Dim choice2
作为字符串的Dim choice3
Dim con作为MySqlConnection
Dim con1作为MySqlConnection
Dim命令作为MySqlCommand
Dim读取为MySqlDataReader
Dim da作为MySqlDataAdapter
将sql设置为字符串
私有子检查加载(发送方作为对象,e作为事件参数)处理MyBase.Load
'将radiobutton设置为false,以便在加载表单时没有阴影按钮'
Label2.Text=1
A.选中=错误
B.选中=错误
C.检查=错误
D.选中=错误
con=新的MySqlConnection
按钮1.已启用=错误
con.ConnectionString=“server=localhost;userid=root;password=;database=user;”
“呼叫潜艇
qno()
端接头
次清除()
'将单选按钮设置为false/no。
A.选中=错误
B.选中=错误
C.检查=错误
D.选中=错误
端接头
子qno()
“呼叫连接”
尝试
con=新的MySqlConnection
con.ConnectionString=“服务器=本地主机;用户id=根;密码=;数据库=用户;”
con.Open()
sql=“从user.math中选择*其中问题\u id=@id;”
COMMAND=newmysqlcommand
指挥
.Connection=con
.CommandText=sql
.Parameters.Clear()
.Parameters.AddWithValue(“@ID”,Label2.Text)
.ExecuteNonQuery()
以
以字节形式显示图像()
Dim dt作为新数据表
da=新的MySqlDataAdapter
da.SelectCommand=命令
da.填充(dt)
如果dt.Rows.Count>0,则
arrImage=dt.行(0).项(7)
将mstream变暗为新的System.IO.MemoryStream(arrImage)
Pic1.Image=Image.FromStream(mstream)
question.Text=dt.Rows(0)。项目(1)
A.文本=dt.行(0)。项目(2)
B.文本=dt.行(0).项目(3)
C.文本=dt.行(0).项目(4)
D.文本=dt.行(0)。项目(5)
其他的
MsgBox(“无结果!”)
如果结束
Catch ex作为MySqlException
MsgBox(例如消息)
最后
con.Close()
da.Dispose()
结束尝试
端接头
次级增量()
'增加答案正确的分数'
尺寸i为整数=0
i=标签2.文本
i=i+1
Label2.Text=i
如果Label2.Text>1,则
按钮1.已启用=真
如果结束
端接头
次减量
'增加答案正确的分数'
尺寸i为整数=1
i=标签2.文本
i=i-1
Label2.Text=i
如果Label2.Text=1,则
按钮1.已启用=错误
如果结束
端接头
私有子按钮2\u单击(发送者作为对象,e作为事件参数)处理按钮2。单击
'检查用户回答问题'
如果((A.Checked=False)和(B.Checked=False)以及(C.Checked=False)和(D.Checked=False)),那么
MsgBox(“请回答问题”)
其他的
“如果考生回答了所有的考试,它将从数据库中调用另一个问题”
如果A.Checked=True,则
con.Open()
"像线一样模糊,
将arren变暗为String=“A”
Dim sql作为字符串=(“从user.math中选择答案,其中问题_id=”&Label2.Text&“”)
COMMAND=newmysqlcommand(sql,con)
把它调暗成线
read=COMMAND.ExecuteReader
如果read.HasRows,则
如果读,那么读
it=阅读项目(“回答”)
如果它=选择,那么
正确=正确+1
Label4.Text=正确

ElseIf it choice和Label2.Text未测试,因为我没有您的数据库。上面和内联的评论

Public Class Form3

    Dim correct As Integer = 0

    Private Sub Exam_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'setting the radiobutton to false, so that when the form load there is no shaded button'
        Label2.Text = "1"
        A.Checked = False
        B.Checked = False
        C.Checked = False
        D.Checked = False
        Button1.Enabled = False
        qno()
    End Sub
    Private Sub clear()
        'to set the radiobutton false/no shaded.
        A.Checked = False
        B.Checked = False
        C.Checked = False
        D.Checked = False
    End Sub

    Private Sub qno()
        Try
            'Using...End Using blocks will close and dispose of your objects
            Using con = New MySqlConnection("server=localhost;userid=root;password=;database=user;")
                Using Cmd = New MySqlCommand("SELECT * FROM user.math WHERE question_id = @ID;", con)
                    Cmd.Parameters.AddWithValue("@ID", Label2.Text)
                    Dim arrImage() As Byte
                    Dim dt As New DataTable
                    Using da = New MySqlDataAdapter
                        da.SelectCommand = Cmd
                        da.Fill(dt)
                        If dt.Rows.Count > 0 Then
                            'Not at all sure about this picture code
                            arrImage = CType(dt.Rows(0).Item(7), Byte())
                            Dim mstream As New System.IO.MemoryStream(arrImage)
                            Pic1.Image = Image.FromStream(mstream)
                            question.Text = dt.Rows(0).Item(1).ToString
                            A.Text = dt.Rows(0).Item(2).ToString
                            B.Text = dt.Rows(0).Item(3).ToString
                            C.Text = dt.Rows(0).Item(4).ToString
                            D.Text = dt.Rows(0).Item(5).ToString
                            'guessing that answer it item 6
                            HiddenLabel.Text = dt.Rows(0).Item(6).ToString
                        Else
                            MsgBox("No results!")
                        End If
                    End Using
                End Using
            End Using
        Catch ex As MySqlException
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'checking of the user answer the questions'
        If ((A.Checked = False) And (B.Checked = False) And (C.Checked = False) And (D.Checked = False)) Then
            MsgBox("Please answer the question")
            Exit Sub
        End If
        'The correct answer was put in the HiddenLabel.Text (Visible set to False)
        'in the qno Sub
        Dim CorrectAnswer As String = HiddenLabel.Text
        Dim UserChoice As String = ""

        If A.Checked Then
            UserChoice = "A"
        ElseIf B.Checked Then
            UserChoice = "B"
        ElseIf C.Checked Then
            UserChoice = "C"
        Else
            UserChoice = "D"
        End If

        If UserChoice = CorrectAnswer Then
            correct += 1
        Else
            'It is very hard to get a good score if it is decremented with every wrong answer
            'Why not skip this and just give a zero for a wrong answer
            correct -= 1
        End If
        Label4.Text = correct.ToString
        clear()
        If Label2.Text = "10" Then
            MessageBox.Show("proceed to other subject test")
            Me.Hide()
            exam2.Show()
        Else
            'Add code to keep track of question number in 
            'Add code to show the next question
        End If

    End Sub

代码太多了,你的问题太模糊了。您需要非常详细地了解这个问题,并且只发布与该问题相关的代码。如果你基本上是说“这就是我所做的,剩下的我该怎么做”那么这不是我们要回答的问题。无论你想做什么,你都需要先尝试去做,然后你可以问为什么它不起作用。然后,您将只发布与该问题相关的代码。启用选项Strict。这将帮助您避免运行时错误。如果您将按钮命名为有意义的名称,这将非常有用。Button2看起来像接受答案,但Button1和Button3没有多大意义。您正在检查Button2中签入的单选按钮,那么为什么所有这些已检查的事件都已更改?请删除子qno中的
.ExecuteNonQuery()
。Select语句是返回行的查询,您可以使用
da.Fill(dt)
执行命令,如果用户希望返回到其他问题并对其进行编辑,该如何操作?如果分数是递减还是不递减,或者分数还是不变,系统将如何处理?如果你允许用户返回并更改答案,他将继续返回,直到看到分数上升。wh