Hi.

I'm trying to make a chat application in Vb what uses MySQL database.

Here is the code for the UpdateChat()sub
Code:
    Public Sub UpdateChat()
        ' MySQL Adapter
        Dim MySQLAdapter As New MySqlDataAdapter
        ' MySQL query
        Dim SQLQuery = "SELECT * FROM chat;"
        ' "Commanerd"
        Dim Command As New MySqlCommand
        ' Select connection for "commander"
        Command.Connection = MainForm.connection
        ' Set query
        Command.CommandText = SQLQuery
        ' MySQL adapter runs query
        MySQLAdapter.SelectCommand = Command
        ' MySQL (Data)reader
        Dim MyData As MySqlDataReader = Command.ExecuteReader
        MyData.Read()
        If (MyData("Id") <= ChatId) Then
            AddChatMessage(MyData("Sender"), MyData("Message"))
            ChatId = ChatId + 1
        End If
        MyData.Close()
    End Sub

    Public Sub AddChatMessage(ByVal Sender As String, ByVal Message As String)
        MainForm.txtChat.Text = MainForm.txtChat.Text + vbCrLf + Sender + ": " + Message
    End Sub
Now it gives me there error that a connection is allready open with the Datareader (I havea timer running this sub once in a while).
But shouldn't this be fixed with this line of code:
Code:
MyData.Close()
?