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

 

  

复制代码
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

posted @   BloggerSb  阅读(612)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示