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