title: How to lock record for editing while using .net
body: <p>Hi Guys I'd like to lock a record to prevent editing when Admin and User want to editing the same record in DB in the same time</p>
  <pre><code>using (SqlCommand cmd = Connection.CreateCommand())
              {
                  cmd.CommandType = CommandType.Text;
                  cmd.CommandText = @&quot;
                      UPDATE   [dbo].[Property]
                      SET     {not important}IS NULL THEN NULL
                                                 ELSE geography::Point(@Location_Lat, @Location_Long, 4326) 
                                              END)
                              {not important}
                      WHERE    [Id] = @Id&quot;;
                  cmd.Parameters.AddParams(property);
                  cmd.Connection.Open();
  
                  try
                  {
                      cmd.ExecuteNonQuery();
                  }
                  finally
                  {
                      cmd.Connection.Close();
                  }
              }
  </code></pre>