title: C# Winforms control - DataGridView - Update Database
body: <p>The programs I am using are WAMP server (and its mysql feature in particular) and MS Visual Studio 2010 and I am programming in C#</p>
  
  <p>Basically, here is what I need and can currently do with my application.</p>
  
  <p>I have several <code>datagridview</code>'s throughout the project and the first is simple, it loads all data from a specific table in the database at the push of a button. I have another form which I can insert records and have somehow managed to make a delete function which asks the user for 2 fields (first name and last name) and then it places these into a query and carries out the command.</p>
  
  <p>What do I need to do?</p>
  
  <p>I need to be able to implement some way for the form to update the database. I have chosen to do this through a <code>datagridview</code> control so the user can see what they are editting whilst they edit it.</p>
  
  <p>I have the following code which I have tried to update the database based on the data in the <code>datagridview</code> control.</p>
  
  <pre><code>string connString = "server=localhost;User Id=root;database=collegelist;";
  MySqlConnection conn = new MySqlConnection(connString);
  string selectSQL = "SELECT * FROM collegeemployee";
  conn.Open();
  MySqlDataAdapter da = new MySqlDataAdapter(selectSQL, conn);
  MySqlCommandBuilder builder = new MySqlCommandBuilder(da);
  DataTable table = new DataTable(); 
  try
  {
      dgView2.Rows.RemoveAt(dgView2.CurrentRow.Index);
      da.Update(table);
  }
  catch (Exception exceptionObj)
  {
      MessageBox.Show(exceptionObj.Message.ToString());
  }
  </code></pre>
  
  <p>the problem with this code (listed in a method obviously) is that while the grid is able to be modified, it is unable to pass the data back to the database.</p>