title: Update SQL Server database with SqlClient
body: <p>I have somehow a problem to update my SQL Server database. I got an "Update" button so the user can change values manually in a DataGridView and then should click a button to save the changes to the database. I use the "Update" command for that but don't know how to manage it.</p>
  
  <p>The button:</p>
  
  <pre><code> private void update_Click(object sender, EventArgs e)
   {     
       sqlCmdBuilder = new SqlCommandBuilder(sqlDatAdapter);
       dataGridView1.DataSource = datTable;
       sqlDatAdapter.Fill(datTable);
       sqlDatAdapter.Update(datTable);    
   }
  </code></pre>
  
  <p>The database gets loaded via another function. In my code I get a <code>NullReferenceException</code>. </p>
  
  <p>How can I catch the existing DataGrid and then register the users changes? </p>
  
  <p>When I define the <code>SqlDatAdapter</code> in the method then the exception doesn't occur anymore but it does absolutely nothing.</p>