title: How to allow CRUD operations in a DataGridView in C#.NET?
body: <p>I've been having a lot of trouble to bind a database (I'm using Northwind) to a DataGridView.
  I've tried various approaches, but none worked for all operations, only some.
  I've also asked on other sites, but so far I haven't gotten any helpful advice.</p>
  
  <p>Is there a tutorial that covers really all CRUD operations (or a combination of several tutorials that together cover all)?</p>
  
  <p>Especially the delete operation is causing me headaches as the only tip I've gotten is to put my delete code into some DataGridView event, yet the problem is that I cannot find a way to determine what exactly the user wants to delete and the KeyDown event won't fire for the delete key.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT:
  Thank you very much. That document is very helpful.
  I have another question though, I have a DataTable as DataSource for the DataGridView.
  To update it for execution of user input CRUD operations, do I need to manually insert data into the DataTable or is it enough to just built a regular SQL command with the adapter's DeleteCommand/InsertCommand/etc properties and then just pass the yet unmodified DataTable as argument in the Update method?</p>
  
  <p>I.e. would this get me the desired result of insert a new row into the db table with the values the user has just input into the DataGridView?</p>
  
  <pre><code>private void DGV_Nwind_UserAddedRow(object sender, DataGridViewRowEventArgs e)
      {
          string sql = "INSERT INTO [" + table.TableName + "] VALUES ("; //sql command base
  
          //add values to command
          for (int i = 0; i &lt; e.Row.Cells.Count; i++)
          {
              sql += "'" + e.Row.Cells[i].ToString() + "'"; 
  
              if (i &lt; (e.Row.Cells.Count - 1)) 
              {
                  sql += ", ";
              }
              else
              {
                  sql += ")";
              }
          }
  
          //update table
          con.OleAdapter.InsertCommand = new OleDbCommand(sql);
          con.OleAdapter.Update(table);
      }
  </code></pre>