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

大家看看,这段代码出错了,要怎么改,谢谢,,在线等,当天结贴!!!!!! 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 ) 为空时,如何作,否则你第一次运行肯定会为空,那你这个代码一定会抛这个异常 __________________________________________________________________________

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...