C# mysqlreader on same connection error
        Posted  
        
            by dominiquel
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by dominiquel
        
        
        
        Published on 2010-06-10T16:38:56Z
        Indexed on 
            2010/06/10
            16:42 UTC
        
        
        Read the original article
        Hit count: 307
        
Hi,
I must find a way to do this in C#, if possible...
I must loop on my folder list (mysql table), and for each folder I instanciate I must do another query, but when I do this it says : "There is already an open DataReader associated with this Connection" and I am inside a mysqlreader loop already.
Note that I have oversimplified the code just to show you, the fact is that I must do queries inside a mysqlreader loop, and it looks to be impossible as they are on the same connection?
MySqlConnection cnx = new MySqlConnection(connexionString);
        cnx.Open();
        MySqlCommand command= new MySqlCommand("SELECT * FROM folder WHERE  folder_id = " + id, cnx);
        MySqlDataReader reader= commande.ExecuteReader();
        while (reader.Read())
        {
            this.folderList[this.folderList.Length] =
                   new CFolder(reader.GetInt32"folder_id"),                                                                             cnx);
        }
        reader.Close();
        cnx.Close();
© Stack Overflow or respective owner