title: c# database update/insert with tableadapter
body: <p>I'm having a "small" question concerning inserting and updating a database in C#. I'm using a table adapter for inserting and updating. The information is coming from an XML file that contains customer information. My primary key is <code>customer_nr</code> which is provided by the XML file.</p>
  
  <p>Now my question is when loading the XML file, somehow I want to check if the database already have the specific <code>customer_nr</code>. If the <code>customer_nr</code> exist, update the database (if the customer changes address this should be updated), else if the <code>customer_nr</code> does not exist insert a new row(with the customers information). </p>
  
  <p>My test code:</p>
  
  <p>(<code>adapter.getCustomerNr</code> is an SQL command in the table adapter where i select all the <code>customer_numbers</code>.)</p>
  
  <pre><code>DataSet1TableAdapters.customer_infoTableAdapter adapter = new DataSet1TableAdapters.customer_infoTableAdapter();
  foreach (var t in customerInfo)
  {
      if (adapter.CustomerNr() != null)
      {
          adapter.Update(t.firstName,t.lastName,t.customerNr);
      }
      else {
          adapter.Insert(t.customerNr, t.firstName, t.lastName); 
      }
  }
  </code></pre>
  
  <p>As I'm very new to C# I'm curious if this even works. But its something that i thought should work. If someone could help me or give me some example how to further go on I would be very grateful.</p>