加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

[VB.NET]大家看看,这段代码出错了,要怎么改,谢谢,,在线等,

发布时间:2020-12-16 23:40:59 所属栏目:大数据 来源:网络整理
导读:大家看看,这段代码出错了,要怎么改,谢谢,,在线等,当天结贴!!!!!! Private Sub addnewitem() Dim nowTable As DataTable = New DataTable( nowCartTable ) nowTable = Session( myCartTable ) Dim data As DataSet With New BusinessRule.Ecom da
大家看看,这段代码出错了,要怎么改,谢谢,,在线等,当天结贴!!!!!! Private Sub addnewitem() Dim nowTable As DataTable = New DataTable( nowCartTable ) nowTable = Session( myCartTable ) Dim data As DataSet With New BusinessRule.Ecom data = .GetPro(ID.Text) End With Dim newDR As DataRow newDR = nowTable.NewRow newDR.Item(0) = ID.Text newDR.Item(1) = data.Tables(0).Rows(0).Item(2) newDR.Item(2) = data.Tables(0).Rows(0).Item(5) newDR.Item(3) = 1 newDR.Item(4) = newDR.Item(2) nowTable.Rows.Add(newDR) Session( myCartTable ) = nowTable End Sub ----------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 147: Dim newDR As DataRow Line 148: Line 149: newDR = nowTable.NewRow Line 150: Line 151: __________________________________________________________________________ nowTable = Session( myCartTable )?? Session是不是一个空值? __________________________________________________________________________ http://msdn2.microsoft.com/zh-cn/library/system.data.datatable.newrow(VS.80).aspx __________________________________________________________________________ Session( myCartTable ) 的值为空 Dim nowTable As DataTable nowTable =(DataTable)Session( myCartTable ) if(nowTable is not nothing) { ........................... } __________________________________________________________________________ 应该是这行出错吧: newDR = nowTable.NewRow 是nowTable为空时出错,这里应该加判断,当Session( myCartTable ) 为空时,如何作,否则你第一次运行肯定会为空,那你这个代码一定会抛这个异常 __________________________________________________________________________

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读