Cannot set Column 'EffectiveDate' to be null. Please use DBNull instead.

时间:2020-11-12 13:57:50   收藏:0   阅读:12
dt.Columns.Add("EffectiveDate", typeof(DateTime));

   DateTime?   effectivedate=null;


  if (lastRow["Effective_x0020_Date"] != DBNull.Value)
  {

     effectivedate = Convert.ToDateTime(lastRow["Effective_x0020_Date"]);
  }


DataRow dr = dt.NewRow();
     dr["EffectiveDate"] = effectivedate;
dt.Rows.Add(dr);

  

Fix

dr["EffectiveDate"] = effectivedate ?? (object)DBNull.Value;

 

 

来源:https://www.codeproject.com/Questions/867120/Cannot-set-Column-EffectiveDate-to-be-null-Please

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!