嘿所有, 字节[] 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
更多推荐
如果它为空,我该怎么办?
发布评论