无法将列'EffectiveDate'设置为null。请改用DBNull。

编程入门 行业动态 更新时间:2024-10-10 05:17:56
本文介绍了无法将列'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。

本文发布于:2023-10-28 10:48:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536417.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   EffectiveDate   null   DBNull

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!