我有这个代码。当我执行一次,我能够得到正确的列表。但是,当我再次运行此方法时,读者没有数据。我在想,在再次调用之前我忘记关闭某些连接,从而导致null结果
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();
}