如果它为空,我该怎么办?

编程入门 行业动态 更新时间:2024-10-26 20:34:51
本文介绍了如果它为空,我该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嘿所有, 字节[] imageData = (字节[])(((DataRowView)fvEmployeeMaster.DataItem).Row.Ite mArray .GetValue(21)); 如果进入的记录为null我得到以下错误信息: 无法投射对象键入''System.DBNull''键入''System.Byte []''。 是否有简写或我需要绕过什么条件语句 这个? 谢谢, rodchar

hey all, Byte[] imageData = (Byte[])(((DataRowView)fvEmployeeMaster.DataItem).Row.Ite mArray.GetValue(21)); If the record coming in is null i get the following error message: Unable to cast object of type ''System.DBNull'' to type ''System.Byte[]''. is there a shorthand or what conditional statement do i need to get around this? thanks, rodchar

推荐答案

" rodchar" < ro ***** @ discussion.microsoft写信息 新闻:BA *********************** *********** @ microsof t ... "rodchar" <ro*****@discussions.microsoftwrote in message news:BA**********************************@microsof t... 嘿all, 字节[] imageData = (字节[])(((DataRowView)fvEmployeeMaster.DataItem).Row.Ite mArray.GetValue(21)); 如果进入的记录为null,我会收到以下错误消息: 无法将类型为''System.DBNull''的对象强制转换为''System.Byte []' '。 我需要一个速记或条件声明吗 这个? hey all, Byte[] imageData = (Byte[])(((DataRowView)fvEmployeeMaster.DataItem).Row.Ite mArray.GetValue(21)); If the record coming in is null i get the following error message: Unable to cast object of type ''System.DBNull'' to type ''System.Byte[]''. is there a shorthand or what conditional statement do i need to get around this?

if(!< some data valueis DBNull) { //继续 }

if (!<some data valueis DBNull) { // proceed }

rodchar写道: rodchar wrote: 嘿所有, Byte [] imageData = (Byte [])(((DataRowView)fvEmployeeMaster.DataItem).Row.Ite mArray.GetValue(21)); 如果进入的记录为null,我会收到以下错误消息: 无法将类型为''System.DBNull''的对象强制转换为''System。字节[]''。 我需要一个速记或条件声明吗 这个? 谢谢, rodchar hey all, Byte[] imageData = (Byte[])(((DataRowView)fvEmployeeMaster.DataItem).Row.Ite mArray.GetValue(21)); If the record coming in is null i get the following error message: Unable to cast object of type ''System.DBNull'' to type ''System.Byte[]''. is there a shorthand or what conditional statement do i need to get around this? thanks, rodchar

使用IsNull方法: byte [ ] imageData; DataRow row =((DataRowView)fvEmployeeMaster.DataItem).Row; if(row.IsNull(21){ imageData = null; } else { imageData =(byte [])row [21]); } 顺便说一句: 不要使用ItemArray属性来访问单个项目。每次使用它时,它会创建所有项目的 数组。使用默认的索引器 ,即row [21]而不是row.ItemArray [21]。 你不必使用GetValue从 数组中获取项目的方法。只需使用默认索引器,即数组(21)而不是 array.GetValue(21)。 - G ??跑安德森 _____ http:// www。 guffa

G ?? ran Andersson写道: G??ran Andersson wrote: 只需使用默认索引器,即数组(21)而不是 array.GetValue(21)。 Just use the default indexer, i.e. array(21) instead of array.GetValue(21).

索引器当然使用括号,而不是parenteses。阵列[21]。 - G ??跑安德森 _____ www.guffa

更多推荐

如果它为空,我该怎么办?

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

发布评论

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

>www.elefans.com

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