title: How to Insert null value for a nullable integer column to SQL Table by C#
body: <p>I am reading a CSV file via OleDBConnection, retrieving integer values for some fields there and saving to SQL DB. I have a column named <code>Q3</code> which is <strong>nullable</strong>.</p>
  <p>When I try the following below, it works well:</p>
  <pre><code>create table #temp (num int);
  insert into #temp (num) values (null);
  </code></pre>
  <p>However, I have the following code in asp.net 4.5, which is not working:</p>
  <pre><code>SQLDatabase sql = new SQLDatabase();
  SQLParamList sqlParams = new SQLParamList();
  
  int? Q3 = null;
  Q3 = CheckNumericContent(r, dr, &quot;Q3&quot;); //Q3 empty cell for the row in csv.
  sqlParams.Add(&quot;@Q3&quot;, Q3); //Q3 is still null here.
  sql.ExecStoredProcedureDataTable(&quot;[spInsert_Data]&quot;, sqlParams);
  </code></pre>
  <p>The code of <code>CheckNumericContent</code> function is here:</p>
  <pre><code>private int? CheckNumericContent(int r, DataRow dr, string columnname)
  {
      int ret = -1;
      if (dr[columnname] != null &amp;&amp; !String.IsNullOrEmpty(dr[columnname].ToString()))
      {
          try
           {
               if (!Int32.TryParse(dr[columnname].ToString(), out ret))
               {
                   ErrorMessage = ErrorMessage + string.Format(&quot;Row {0}: {1) is not numeric.\n&quot;, r.ToString(), columnname);
               }
           }
           catch (Exception ex)
           {
              ErrorMessage = ErrorMessage + &quot;some error: &quot;+ex.ToString(); 
           }
            return ret;
      }
      else
      {
          return null;
      }          
  }
  </code></pre>
  <p><strong>spInsert_Data stored Procedure is (Sql Server 2014):</strong></p>
  <pre><code>CREATE PROCEDURE spInsert_Data
     @Q3 int
  AS BEGIN
     insert into tblMyData (Q3) values (@Q3);
  END
  </code></pre>
  <p>This code works well unless Q3 is null. When Q3 is null, which means there is no data for Q3 for a row in the CSV, it is giving the error:</p>
  <blockquote>
  <p>Procedure or function 'spInsert_Data' expects parameter '@Q3', which
  was not supplied.</p>
  </blockquote>
  <p>Picture of the error is on the below. What is wrong and how can I fix it? Any help would be appreciated!</p>
  <p><a href="https://i.stack.imgur.com/0oXme.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0oXme.png" alt="enter image description here" /></a></p>