title: Specified cast is not valid when I try to cast to (int?)
body: <p>I have this code to save data to database</p>
  
  <pre><code>for (int i = 0; i &lt; dt.Rows.Count; i++)
          {
              var row = dt.Rows[i];
  
              await stock.AddProjectNeedsBoltsTest(Convert.ToInt32(row["Quantité"]),
                  (int?)row["Filetage"],
                  Convert.ToInt32(row["idProject"]),
                  (int?)row["idCategory"],
                  (int?)row["idType"]).ConfigureAwait(true);
          }
  </code></pre>
  
  <p>and this the code behind  AddProjectNeedsBoltsTest</p>
  
  <pre><code>public async Task AddProjectNeedsBoltsTest(int Quantity, int? Filetage, int IdProject, int? IdCategory, int? IdType)
      {
          DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
          await Task.Run(() =&gt; DAL.Open()).ConfigureAwait(false);
          SqlParameter[] param = new SqlParameter[5];
  
          param[0] = new SqlParameter("@Quantity", SqlDbType.Int)
          {
              Value = Quantity
          };
  
          param[1] = new SqlParameter("@Filetage", SqlDbType.Int)
          {
              Value = Filetage.HasValue ? Filetage : (object)DBNull.Value
          };
  
          param[2] = new SqlParameter("@IdProject", SqlDbType.Int)
          {
              Value = IdProject
          };
  
          param[3] = new SqlParameter("@IdCategory", SqlDbType.Int)
          {
              Value = IdCategory.HasValue ? IdCategory : (object)DBNull.Value
          };
  
          param[4] = new SqlParameter("@IdType", SqlDbType.Int)
          {
              Value = IdType.HasValue ? IdType : (object)DBNull.Value
          };
  
          await Task.Run(() =&gt; DAL.ExcuteCommande("AddProjectNeedsBoltsTest", param)).ConfigureAwait(false);
          DAL.Close();
  
      }
  </code></pre>
  
  <p>and this is my stored procedure</p>
  
  <pre><code>    CREATE PROCEDURE dbo.AddProjectNeedsBoltsTest
          @Quantity int
         ,@Filetage int
         ,@IdProject int
         ,@IdCategory int
         ,@IdType int
  AS
  INSERT INTO [dbo].[ProjectNeedsBolts]
         ([Quantity]
         ,[Filetage]
         ,[IdProject]
         ,[IdCategory]
         ,[IdType])
   VALUES
         (@Quantity
         ,@Filetage
         ,@IdProject
         ,@IdCategory
         ,@IdType)
  </code></pre>
  
  <p>Now when I click on save button I get this error</p>
  
  <blockquote>
    <p>An exception of type 'System.InvalidCastException' occurred in Smart Industrial Management.exe but was not handled in user code
    Additional information: Specified cast is not valid.</p>
  </blockquote>
  
  <p>On debugging on this line of code</p>
  
  <pre><code>(int?)row["Filetage"]
  </code></pre>
  
  <p>I get this error message</p>
  
  <blockquote>
    <p>Cannot unbox 'row["Filetage"]' as a 'int?'</p>
  </blockquote>
  
  <p>Update:This is my datatable</p>
  
  <pre><code>DataTable dt = new DataTable();
      void CreateDataTable()
      {
          dt.Columns.Add("Quantité");
          dt.Columns.Add("Filetage");
          dt.Columns.Add("idProject");
          dt.Columns.Add("idCategory");
          dt.Columns.Add("idType");
  
          gridControl1.DataSource = dt;
      }
  </code></pre>
  
  <p>If I try with </p>
  
  <pre><code>dt.Columns.Add("Filetage", typeof(int?));
  </code></pre>
  
  <p>I get error message</p>
  
  <blockquote>
    <p>DataSet does not support System.Nullable&lt;></p>
  </blockquote>