Я столкнулся с проблемой в моей системе входа.
Это мое кодирование: я уже добавляю ссылку MySQL.Data в мою форму. Когда я нажимаю кнопку, это сообщение об ошибке отображается. (Первая ошибка исключения типа «System.Collections.Generic.KeyNotFoundException» произошла в mscorlib.dll) .
Imports MySql.Data.MySqlClient
Public Class Form1
Public conn As MySqlConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conn = New MySqlConnection("server=localhost; user id=root; password=; database=test")
Try
conn.Open()
Dim sqlquery As String = "SELECT * FROM yy WHERE Username = '" & TextBox1.Text & "';"
Dim data As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.CommandText = sqlquery
command.Connection = conn
adapter.SelectCommand = command
data = command.ExecuteReader
While data.Read()
If data.HasRows() = True Then
If data(2).ToString = TextBox2.Text Then
MsgBox("Login")
Else
MsgBox("Failed Login")
End If
Else
MsgBox("Failed Login")
End If
End While
Catch ex As Exception
End Try
End Sub
End Class