title: How to make optional parameter in parameterizaed query
body: <p>In my code bellow I use simple parameterized query.<br/>
  It has a lot parameters and some can be <strong>NULL</strong> and some when null <strong>complain about FK</strong>.<br/>
  How can I fix this to have optional parameters but <strong>without using stored procedure</strong>.<br/>
  To be clear I want when parameter is null to avoid trying to update that field.</p>
  
  <pre><code>conn.Open();
  
                  string sql = @"UPDATE UserProfile
                                 SET FirstName = @p_FirstName
                                    ,LastName = @p_LastName
                                    ,Gender = @p_Gender
                                    ,DateOfBirth = @p_DateOfBirth
                                    ,CityId = @p_CityId
                                    ,MartialStatusId = @p_MartialStatusId
                                    ,ProfileImageId = @p_ProfileImageId
                               WHERE UserId = @p_UserId";
  
                  using (SqlCommand cmd = new SqlCommand(sql, conn))
                  {                    
                      cmd.Parameters.AddWithValue("@p_FirstName", userProfile.FirstName);
                      cmd.Parameters.AddWithValue("@p_LastName", userProfile.LastName);
                      cmd.Parameters.AddWithValue("@p_Gender", userProfile.Gender);
                      cmd.Parameters.AddWithValue("@p_DateOfBirth", userProfile.DateOfBirth);
                      cmd.Parameters.AddWithValue("@p_CityId", userProfile.CityId);
                      cmd.Parameters.AddWithValue("@p_MartialStatusId", userProfile.MartialStatusId);
                      cmd.Parameters.AddWithValue("@p_ProfileImageId", userProfile.ProfileImageId);
                      cmd.Parameters.AddWithValue("@p_UserId", userProfile.UserId);
  
                      cmd.ExecuteNonQuery();
  
                  }
  </code></pre>