无法显示mysql查询的结果

时间:2015-01-29 16:05:11

标签: mysql vb.net

我是Visual Basic的新手,我非常精通php,这就是我转向VB的原因。我无法获取数据并显示它。这是我的完整代码,应该在我的数据库中找到#34;游戏",找到包含用户名的行#34; kenazz"并显示用户名" kenazz"。

Imports MySql.Data.MySqlClient
Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim cs As String = "Database=game;Data Source=localhost;" _
        & "User Id=root;Password="

    Dim conn As New MySqlConnection(cs)

    Try
        conn.Open()
        Dim stm As String = "SELECT * FROM users WHERE users.username = 'Kenazz'"
        Dim cmd As MySqlCommand = New MySqlCommand(stm, conn)
        Dim reader As MySqlDataReader = cmd.ExecuteReader()

        While reader.Read()
            Console.WriteLine(reader.GetInt32("id") & ": " _
                & reader.GetString("username"))
        End While

        reader.Close()

    Catch ex As MySqlException
        Console.WriteLine("Error: " & ex.ToString())
    Finally
        conn.Close()
    End Try

End Sub
End Class

我哪里错了?

0 个答案:

没有答案