2016-07-15 35 views
0

我想在Vb.net中使用MySQL進行聊天,我想將聊天加載到列表框中,其中(用戶名)'par''和(消息)。Vb.net Mysql在一個數據中的多個查詢

但它不斷顯示我的錯誤,我不明白如何解決它。

這裏是我的代碼:

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--了---問題---

End While 

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

請張貼錯誤是什麼如果你說只有錯誤將如何o他們明白。 –

回答

1

你可以試試這個:

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

最好的問候

+0

謝謝!它完美地工作! :) –