Visual Basic 2010无法连接PHPMYADMIN(离线)

时间:2013-01-09 15:08:40

标签: visual-studio-2010 phpmyadmin

我在登录系统中遇到问题。 这是我的编码:我已经在我的表单中添加了引用MySQL.Data。当我单击按钮时,会显示此错误消息。 (mscorlib.dll中出现'System.Collections.Generic.KeyNotFoundException'类型的第一次机会异常)

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

0 个答案:

没有答案