0

I have this code. When I execute this once, I am able to get the correct list. But when I run this method again, the reader has no data. I was thinking did I forget to close some connection before calling it again, thus leading to the null result

 public IEnumerable<List<string>> retreiveList()
 {
        string query = "SELECT * FROM table1;";
        MySqlCommand cmd = new MySqlCommand(query, connection);
        MySqlDataReader reader;
        reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            List<string> toReturn=new List<string>();
            for (int i = 0; i < reader.FieldCount; i++)                
                toReturn.Add(reader[i].ToString());
            yield return toReturn;
        }
        reader.Close();         
    }
user3398315
  • 331
  • 6
  • 17

0 Answers0