大家看看,这段代码出错了,要怎么改,谢谢,,在线等,当天结贴!!!!!!
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:
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:
---------------------------
说是没有实例化遍历,,,
为什么阿
[解决办法]
Dim newDR As DataRow
->
Dim newDR As New DataRow
??
[解决办法]
nowTable = Session( "myCartTable ")==> 可能是session中没有值
[解决办法]
nowTable = Session( "myCartTable ")
为空,你遍历就没有东西了,
注意检查session看看,先打印出来看有没有
[解决办法]
nowTable = Session( "myCartTable ")
这句
你在哪定义Session( "myCartTable ")的?
[解决办法]
为什么要把Table放到session里?
会很慢