I wrote a tiny software that retrieves some data from a MySQL database and shows them through labels in a table format. Now for each "row" (or information) the user has the possibility to remove that info from the MySQL Database. So, that's some piece of code:
public Form1()
{
   InitializeComponent();
   MySqlConnection conn = null;
   MySqlDataReader mainrdr = null;
   if (open_connection()) //open_connection simply opens a connection to MySQL DB and returns true or false according if the connection was opened with success or something else.
   {
      string query = "SELECT * FROM res_ev;";
      MySqlCommand cmd = new MySqlCommand(query, conn);
      mainrdr = cmd.ExecuteReader();
      While(mainrdr.Read())
      {
        Label label = new Label();
        Button button = new Button();
        ...
        ... //DEFINING PROPERTY OF THESE OBJECTS
        ...
        string inform = mainrdr.GetString(0);
        button.Click += new EventHandler((s, e) => remove(s, e, inform));
        ...
        ...
      }
      ...
   }
}
private void remove(object sender, EventArgs e, string info)
{
   MessageBox.Show(info);
   ...
   ...
}
The problem is:
The string "inform" during the While clause assumes Always the right information
For ex.
- Loop 1 
 inform is- Apple
 and in- button.Clickin- removefunction- informis- Apple;
- Loop 2 
 inform is- Book
 and in- button.Clickin- removefunction- informis- Book;
- Loop 3 
 inform is- Marshmallow
 and in- button.Clickin- removefunction- informis- Marshmallow
but when I click each button dynamically created, all shows up the last string that was assumed by inform during the While clause.
So I want that if I click the first button (created in loop 1) it has to show "Apple", the second one "Book" and the last one "Marshmallow".
Any idea to resolve that?
 
     
    