title: Passing parameter to stored procedure from C#: Which SQLDbType to use for numeric(18, 0)
body: <p>I have a stored procedure in SQL Server which has an output parameter pf type <code>numeric(18,0)</code>. From C# I create a <code>SqlParameter</code> with a <code>SqlDbType.Decimal</code> and I set precision to 18 and scale to 0.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>queryParameters[2] = new SqlParameter("@Id", SqlDbType.Decimal);
  queryParameters[2].Precision = 18; // # digits
  queryParameters[2].Scale = 0;      // # decimals
  queryParameters[2].Direction = ParameterDirection.Output;
  </code></pre>
  
  <p>The stored procedure is executed correctly, and returns output parameter correctly, but when I parse this into a long variable in C# as below:</p>
  
  <pre><code>long id = (long)queryParameters[2].Value;
  </code></pre>
  
  <p>it says cannot convert it.</p>
  
  <p>But if I modify the <code>SqlParameter</code> type to <code>SqlDbType.Bigint</code>, then it works. </p>
  
  <p>So it is correct what I am doing by passing it as <code>SqlDbType.BigInt</code>? Or is better to pass it as <code>SqlDbType.Decimal</code> and then use a decimal C# variable instead of long?</p>
  
  <p>Passing it as <code>SqlDbType.Decimal</code> and then doing below is also working:</p>
  
  <pre><code>decimal id = (decimal)queryParameters[2].Value;
  </code></pre>
  
  <p>So what approach is the best taken into account that this number is an integer without decimals?</p>