简体   繁体   English

vb.net(附加信息:'where 子句'中的未知列'Secret_question')

[英]vb.net(Additional information: Unknown column 'Secret_question' in 'where clause')

Imports MySql.Data.MySqlClient
Public Class Forgot_password
    Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim con As New MySqlConnection("host=localhost;username=root; password=godzilla408421;database=program")
        Dim cmd As New MySqlCommand
        Dim dr As MySqlDataReader

        con.Open()
        cmd.Connection = con
        cmd.CommandText = "SELECT * FROM program.login where Username ='" & useridtxt.Text & "' and Secret_question='" & questiontxt.Text & "' and answer='" & answertxt.Text & "'"
        dr = cmd.ExecuteReader <<<<(HERE IS MY PROBLEM,IT TELLS ME THAT,"UNKNOW COLUMN'SECRET_QUESTION IN WHERE CLAUSE',PLEASE PLEASE PLEASE HELP"0>>>>
        If Not dr Is Nothing Then
            dr.Read()
            passwordtxt.Text = dr(1)
            dr.Close()
        Else
            MsgBox("Usename or password doesnt match")


        End If
    End Sub
End Class

First check your table whether you have Secret_question field or not, maybe you put it plural like Secret_questions.首先检查你的表是否有Secret_question 字段,也许你把它像Secret_questions 一样复数。 Then it's better to modify your code a bit like the following那么最好像下面这样修改你的代码

cmd.CommandText = "SELECT * FROM program.login where Username =?Username and Secret_question=?Secret_question and answer=?answer;"
 cmd.Parameters.AddWithValue("?Username", useridtxt.Text.Trim())
 cmd.Parameters.AddWithValue("?Secret_question", questiontxt.Text.Trim())
 cmd.Parameters.AddWithValue("?answer", answertxt.Text.Trim())
 dr = cmd.ExecuteReader 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM