title: get sql error code in code behind in asp.net C#
body: <p>So, I am getting an exception in Stored Procedure whose error code is 547. I have created a data diagram in sql server, where I have defined the relationships.when I run the any delete SP I get an error saying FK conflict, which is right. My problem is how do I get the number(i.e 547) in my C# code.</p>
  
  <pre><code>catch (Exception ex)
          {
  
              lblMessage.Text = ex.Message;
          }
  </code></pre>
  
  <p>I sthere any way where I can get this 547 code in my C# code.? Like </p>
  
  <pre><code> ex.somethin (which gives me the error message's code).
  </code></pre>