在使用mysql在answer.text=dr(1)或question.text=dr(3)处调用read()之前访问字段的尝试无效,请单击“获取密码”

3ks5zfa0  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(202)
Imports MySql.Data.MySqlClient

Public Class Forgot_Password_form
    Dim con As New MySqlConnection("host=localhost;username=root;password=system;database=bike")
    Dim cmd As New MySqlCommand
    Dim dr As MySqlDataReader
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "select * from login where userid='" & useridtxt.Text & "'and question='" & question.Text & "'and answer='" & answertxt.Text & "'"
            dr = cmd.ExecuteReader
            If Not dr Is Nothing Then
                dr.Read()
                answer.Text = dr(1)
                dr.Close()
            End If
        Catch ex As Exception
            MessageBox.Show("UserID or answer is incorrect")
        End Try
        con.Close()

    End Sub

    Private Sub Exit__Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Exit_.Click
        End
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Login_Menu.Show()
        Me.Hide()
    End Sub

    Private Sub useridtxt_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles useridtxt.LostFocus
        Try
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "select * from login where userid='" & useridtxt.Text & "'"
            dr = cmd.ExecuteReader
            If Not dr Is Nothing Then
                dr.Read()
                question.Text = dr(3)
                dr.Close()
            End If
        Catch ex As Exception

        End Try
    End Sub

End Class

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题