无法将列'EffectiveDate'设置为null。请改用DBNull。 [英] Cannot set Column 'EffectiveDate' to be null. Please use DBNull instead.
本文介绍了无法将列'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跟随很多东西
http://codeverge.com/asp.net.presentation-controls/how- to-return-dbnull.value-inst / 487162 [ ^ ]
但同样的错误我正在获取
解决方案
只是因为lastRow [Effective_x0020_Date]是DBNull吗?那么你将在effectivedate中得到初始值(null);
在分配数据行值时,尝试使用空合并运算符
< pre lang =c#> 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
http://codeverge.com/asp.net.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。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文