title: Check if a record exists in the database
body: <p>I am using these lines of code to check if the record exists or not.</p>
  <pre><code>SqlCommand check_User_Name = new SqlCommand(&quot;SELECT * FROM Table WHERE ([user] = '&quot; + txtBox_UserName.Text + &quot;') &quot;, conn);
  
  int UserExist = (int)check_User_Name.ExecuteScalar();
  </code></pre>
  <p>But I am getting an error:</p>
  <blockquote>
  <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  <p>I want to do:</p>
  <pre><code>if (UserExist &gt; 0)
      // Update record
  
  else
  
      // Insert record
  </code></pre>