title: "Specified Cast is invalid" Error in WinForm application
body: <p>I am using Microsoft Visual Studio Community version 2015. There have been many questions on this issue, but my problem was not covered in them completely. Basically i am working in Windows Form Application (C#) with MySql(phpmyadmin - wamp) database. I am creating a simple windows form application to get Input, Update/Delete the data, Display the elements in Data Grid View and Search any record. I am facing problem in Updating the record. Compiler continuously gives me the same error, that is; "Specified Cast is Invalid". My Code is given bellow:
  .</p>
  
  <pre><code>private void button_update(object sender, EventArgs e)
  {
  try
     { 
      MySqlConnection cn = new MySqlConnection("server=localhost;port=3306;database=hyder;uid=root;Encrypt=false;AllowUserVariables=True;Usecompression=True;");
      int id = (int)dataGridView1.SelectedRows[0].Cells[0].Value;
      cn.Open();
      MySqlCommand cmd = new MySqlCommand();
      cmd.Connection = cn;
      cmd.CommandType = CommandType.Text;
      cmd.CommandText = "update record set r_name='" + textBox1.Text + "',r_address='" + textBox2.Text + "',r_phone='" + textBox3.Text + "',r_comment='" + textBox4.Text + "' where r_id='" + id;
      cmd.ExecuteNonQuery();
      MessageBox.Show("Record Updated!");
      cn.Close();
   }
  catch (Exception x) { MessageBox.Show("Error:" + x.Message); }
  }
  </code></pre>
  
  <hr>
  
  <p>What is the problem with this code ?</p>