【问题标题】:Vb.net Mysql Multiple queries in one dataVb.net Mysql 一个数据中的多个查询
【发布时间】:2016-07-15 06:00:55
【问题描述】:

我正在尝试使用 MySQL 在 Vb.net 中进行聊天,我想将聊天加载到一个列表框中,其中将是(用户名)“par”和(消息)。

但它一直向我显示错误,我不明白如何解决它。

这是我的代码:

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


    Dim stringConn As String
    Dim stringCmd As String
    Dim myConn As MySqlConnection
    Dim myCmd As MySqlCommand


    stringCmd = "SELECT par, message FROM chat"


    stringConn = "server=localhost; user id=studio; password=mypw; database=studio;"


    myConn = New MySqlConnection(stringConn)


    myCmd = New MySqlCommand(stringCmd, myConn)

    myConn.Open()


    Dim myReader As MySqlDataReader


    myReader = myCmd.ExecuteReader()

    'Reset your List box here.
    ListBox1.Items.Clear()

    While myReader.Read()
       --------------Here is my problem ---------------
        ListBox1.Items.Add(myReader.GetString(1//username//) & " " & myReader.GetString(2//message//))

----结束---问题---

    End While

    myReader.Close()
    myConn.Close()
End Sub

【问题讨论】:

  • 请发布错误是什么。如果你说错误,其他人会如何理解。

标签: mysql .net vb.net datareader


【解决方案1】:

你可以试试这个:

If myReader.HasRows = True Then
    Do While myReader.Read()
        ListBox1.Items.Add(myReader(0) & " " & myReader(1))
    Loop
End If

最好的问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-21
    • 2012-01-13
    • 2019-03-22
    • 2023-03-17
    • 2012-02-16
    • 2017-02-18
    • 1970-01-01
    • 2014-11-09
    相关资源
    最近更新 更多