0
如果用户名和密码插入正确,我已经创建了一个代码来显示正确的消息。用户的用户名和密码是从数据库表中提取的。但我总是收到用户名和密码不正确的消息。我不知道为什么。这是我的代码连接Mysql数据库和visual basic
私人小组Button2_Click(BYVAL发件人为System.Object的,BYVALË作为System.EventArgs)把手btnLogIn.Click MySqlConn =新的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循环至少会执行一次。其次,你应该考虑不将密码存储为纯文本。 – MaCron