本文介绍了无法将列'EffectiveDate'设置为null。请改用DBNull。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到错误无法将列'EffectiveDate'设置为null。请改用DBNull。 我的代码是
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);i跟随很多东西 codeverge/asp.presentation-controls/how- to-return-dbnull.value-inst / 487162 [ ^ ] 但同样的错误我正在获取
解决方案只是因为lastRow [Effective_x0020_Date]是DBNull吗?那么你将在effectivedate中得到初始值(null); 在分配数据行值时,尝试使用空合并运算符 dr [ EffectiveDate] = effectivedate ?? DBNull.Value;
hi, i am getting error Cannot set Column 'EffectiveDate' to be null. Please use DBNull instead. my code is
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);i followed many things codeverge/asp.presentation-controls/how-to-return-dbnull.value-inst/487162[^] but same error i am getting
解决方案 COuld it simply be that lastRow["Effective_x0020_Date"] is DBNull? Then you would have the initial value (null) in effectivedate; When assigning the data row value, try using null coalescing operator dr["EffectiveDate"] = effectivedate ?? DBNull.Value;更多推荐
无法将列'EffectiveDate'设置为null。请改用DBNull。
发布评论