title: SQL update statement in C#
body: <p>I have table  <strong>"Student"</strong></p>
  
  <pre><code>   P_ID   LastName  FirstName  Address  City
  
     1        Hansen    Ola                
     2        Svendson   Tove
     3        Petterson   Kari
     4        Nilsen       Johan
  ...and so on 
  </code></pre>
  
  <p>How do i change edit code in C#</p>
  
  <pre><code> string firstName = "Ola";
   string  lastName ="Hansen";
   string  address = "ABC";
   string city = "Salzburg";
  
   string connectionString = System.Configuration.ConfigurationManager
                            .ConnectionStrings["LocalDB"].ConnectionString;
  
   using (SqlConnection connection = new SqlConnection(connectionString))
       using (SqlCommand command = connection.CreateCommand())
   { 
     command.CommandText = "INSERT INTO Student (LastName, FirstName, Address, City) 
                            VALUES (@ln, @fn, @add, @cit)";
  
     command.Parameters.AddWithValue("@ln", lastName);
     command.Parameters.AddWithValue("@fn", firstName);
     command.Parameters.AddWithValue("@add", address);
     command.Parameters.AddWithValue("@cit", city);
  
     connection.Open();
  
     command.ExecuteNonQuery();
  
     connection.Close();
   } 
  </code></pre>
  
  <p>to edit entry  where <strong>Lastname</strong> field has lastname value and <strong>FirstName</strong> field has firstname  value.  </p>
  
  <p>I dont want to use like this </p>
  
  <pre><code> UPDATE Persons  SET Address='Nissestien 67', City='Sandnes' 
   WHERE LastName='Tjessem'     AND FirstName='Jakob'
  </code></pre>
  
  <p>and i edited my original statement to </p>
  
  <pre><code> command.CommandText = "UPDATE Student(LastName, FirstName, Address, City) 
     VALUES (@ln, @fn, @add, @cit) WHERE LastName='" + lastName + 
                             "' AND FirstName='" +  firstName+"'";
  </code></pre>
  
  <p>but the statement is not getting executed, why is it throwing SQL exception ? Is there nay solution to it ?</p>