title: Datagridview cell value change update database
body: <p>I have retrieved data from Mysql database into a DataGridView1. Let us suppose I am in Row 0. When I change the contents of Row 0, Cell 1 and press enter key or a button, the Update query should modify that row, but I am unable to modify the value of the cell. The cell maintains its previous value when i reload data and the database is not modified. For example, if I change the contents of a cell under column Client_Name  from "Acs" to "Gmt", how can I change the value of the cell from "Acs" to "Gmt"? and to have it updated into Mysql database, I am using c# in Vs 2012. below is my code that retrieves my database into datagridview1 any help is welcomed thanks.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using MySql.Data;
  using MySql.Data.MySqlClient;
  using System.Configuration;
  using System.Data.SqlClient;
  
  namespace PI.Gen
  {
      public partial class frmMain : Form
      {
          MySqlConnection Conn;
  
  
          public frmMain()
          {
              InitializeComponent();
              btnDisconnect.Enabled = true;
              btnLoadData.Enabled = false;
              btnLoadClients.Enabled = false;
  
          }
  
  
  
  
  
          private void btnConnect_Click(object sender, EventArgs e)
          {
  
              string strConnect = "server=" + txtServer.Text + ";uid=" + txtUsername.Text + ";pwd=" + txtPassword.Text + ";database=" + txtDatabase.Text;
              try
              {
                  if (txtServer.TextLength &lt;= 0 || txtUsername.TextLength &lt;= 0 || txtDatabase.TextLength &lt;= 0)
                  {
                      MessageBox.Show("You have an empty database connection field. Please supply a valid value.");
                      return;
                  }
  
                  Conn = new MySqlConnection(strConnect);
                  Conn.Open();
  
                  if (Conn.State.ToString() != "Open")
                  {
                      MessageBox.Show("Could not open database connection");
                      return;
                  }
                  btnDisconnect.Enabled = true;
                  btnConnect.Enabled = false;
                  btnLoadData.Enabled = true;
                  btnLoadClients.Enabled = true;
                  //  btnSubmitClient.Enabled = true;
              }
              catch (Exception ex)  // catch on general exceptions, not specific
              {
                  MessageBox.Show(ex.Message);
                  return;
              }
          }
  
  
  
          private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
          {
              if (Conn != null)
              {
                  Conn.Close();
              }
          }
  
          private void btnDisconnect_Click(object sender, EventArgs e)
          {
              try
              {
                  Conn.Close();
                  Conn = null;
                  btnDisconnect.Enabled = false;
                  btnConnect.Enabled = true;
                  btnLoadData.Enabled = false;
                  btnLoadClients.Enabled = false;
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);
                  return;
              }
          }
  
  
  
  
  
          private void btnLoadData_Click(object sender, EventArgs e)
          {
              try
              {
                  string CmdString = "SELECT * FROM t_receipients";
                  MySqlDataAdapter sda = new MySqlDataAdapter(CmdString, Conn);
                  DataSet ds = new DataSet();
  
                  sda.Fill(ds);
                  dataGridView1.DataSource = ds.Tables[0].DefaultView;
  
  
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);
                  return;
              }
  
           }
  
  
          private void btnLoadClients_Click(object sender, EventArgs e)
          {
              try
              {
  
                  string CmdString = "SELECT * FROM t_clients";
                  MySqlDataAdapter sda = new MySqlDataAdapter(CmdString, Conn);
  
                  DataSet ds = new DataSet();
                  sda.Fill(ds);
                  dataGridView1.DataSource = ds.Tables[0].DefaultView;
  
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);
                  return;
              }
  
          }
  </code></pre>