【发布时间】:2017-06-21 13:12:37
【问题描述】:
如果用户名和密码正确插入,我已经创建了一个代码来显示正确的消息。用户的用户名和密码是从数据库表中提取的。但我总是收到用户名和密码不正确的消息。我不知道为什么。这是我的代码:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogIn.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = "server=localhost;userid=root;password=12345;database=environment"
Dim READER As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "select * from environment.customers where customer_name='" & txtUser.Text & "'and customer_detail='" & txtPass.Text & " '"
COMMAND = New MySqlCommand(Query, MySqlConn)
READER = COMMAND.ExecuteReader
Dim count As Integer
count = 0
While READER.Read
count = count + 1
End While
If count = 1 Then
MessageBox.Show("username and password are correct")
ElseIf count > 1 Then
MessageBox.Show("username and password are duplicate")
Else
MessageBox.Show("username and password are incorrect")
End If
MySqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
【问题讨论】:
-
简短的回答是 count 将始终至少为 1。无论结果如何,while 循环都会至少执行一次。其次,您应该考虑不要将密码存储为纯文本。
标签: mysql sql vb.net visual-studio