string connectionString = ConfigurationManager.AppSettings["AllRttpDBConnectionString"];
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlCommand command = connection.CreateCommand();
command.CommandText = "Select * from test where ServiceName like 'T%' " ;
try
{
connection.Open();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
try
{
MySqlDataReader reader;
reader = command.ExecuteReader();
while (reader.Read())
{
Player.Name = reader["Name"].ToString();
Player.Number = Convert.ToInt32(reader["Number"].ToString());
//push to list
PlayerList.Add(Player);
}
connection.Close();
}
catch (Exception e)
{
connection.Close();
logger.Info(e.ToString());
}
Above is the code I am using to read multiple rows from a database into a list. However, all my list items have the exact same data (the last row of the database).
I know its probably a really simple, stupid mistake, but I just can't see it.