title: How to update a database with new information
body: <p>I am terrible with databases so please bear with me.</p>
  
  <p>I have a program that gets some user information and adds it to a database table. I then later need to get more information for that table, and update it. To do so I have tried doing this:</p>
  
  <pre><code>    public static void updateInfo(string ID, string email, bool pub)
      {
          try
          {
              //Get new data context
              MyDataDataContext db = GetNewDataContext(); //Creates a new data context
  
              //Table used to get user information
              User user = db.Users.SingleOrDefault(x =&gt; x.UserId == long.Parse(ID));
  
              //Checks to see if we have a match
              if (user != null)
              {
                  //Add values
                  user.Email = email;
                  user.Publish = publish;
              }
  
              //Prep to submit changes
              db.Users.InsertOnSubmit(user);
              //Submit changes
              db.SubmitChanges();
          }
          catch (Exception ex)
          {
              //Log error
              Log(ex.ToString());
          }
      }
  </code></pre>
  
  <p>But I get this error:</p>
  
  <p>
      System.InvalidOperationException: Cannot add an entity that already exists.</p>
  
  <p>I know this is because I already have an entry in the table, but I don't know how to edit the code to update, and not try to make a new one?</p>
  
  <p>Why does this not work? Wouldn't submitting changes on a current item update that item and not make a new one?</p>