title: Updating MS Access Database from Datagridview
body: <p>I am trying to update an ms access database from a datagridview.</p>
  
  <p>The datagridview is populated on a button click and the database is updated when any cell is modified.</p>
  
  <p>The code example I have been using populates on form load and uses the cellendedit event.</p>
  
  <pre><code>private OleDbConnection connection = null;
  private OleDbDataAdapter dataadapter = null;
  private DataSet ds = null;
  private void Form2_Load(object sender, EventArgs e)
  {
  
      string connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\\Users\\Peter\\Documents\\Visual Studio 2010\\Projects\\StockIT\\StockIT\\bin\\Debug\\StockManagement.accdb';Persist Security Info=True;Jet OLEDB:Database Password=";
      string sql = "SELECT * FROM StockCount";
      connection = new OleDbConnection(connetionString);
      dataadapter = new OleDbDataAdapter(sql, connection);
      ds = new DataSet();
      connection.Open();
      dataadapter.Fill(ds, "Stock");
      connection.Close();
  
      dataGridView1.DataSource = ds;
      dataGridView1.DataMember = "Stock";
  
  }
  private void addUpadateButton_Click(object sender, EventArgs e)
  {
  
  }
  
  private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  {
      try
      {
          dataadapter.Update(ds,"Stock");
      }
      catch (Exception exceptionObj)
      {
          MessageBox.Show(exceptionObj.Message.ToString());
      }
  }
  </code></pre>
  
  <p>The error I receive is </p>
  
  <blockquote>
    <p>Update requires a valid UpdateCommand when passed DataRow collection
    with modified rows.</p>
  </blockquote>
  
  <p>I'm not sure where this command needs to go and how to reference the cell to update the value in the database.</p>