[VB.NET]大家看看,这段代码出错了,要怎么改,谢谢,,在线等,当天结贴!!!!!!
2008-12-29 01:06
465 查看
<script type="text/javascript"><!--
google_ad_client = "pub-8333940862668978";
/* 728x90, 创建于 08-11-30 */
google_ad_slot = "4485230109";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
大家看看,这段代码出错了,要怎么改,谢谢,,在线等,当天结贴!!!!!!
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 )
为空时,如何作,否则你第一次运行肯定会为空,那你这个代码一定会抛这个异常
__________________________________________________________________________
相关文章推荐
- [VB.NET]看看下面的代码,怎么没有错误提示呀!!!!!!
- [VB.NET]引用和值类型的区别? 分不清了,麻烦大家看看我的代码.
- [VB.NET]请教vb.net写代码用什么平台?谢谢
- 在线VB.NET与C#代码互相转换!
- [VB.NET]100分求一小段代码 ~~ 在线等 ~~ 当日揭帖
- [VB.NET]请教在一段代码中怎么提取图片路径
- C#与VB.NET代码互相转换在线工具
- [VB.NET]高手写的一句代码,我没见过.请帮我解释解释!!! 谢谢!!!
- [VB.NET]数组为什么出错啊?急!!1在线等~~~
- [VB.NET]请问连接access的代码怎么写?
- 实用的在线工具:C#和VB.net代码互转
- 在线工具--把C#代码转换VB.NET代码(相互转换)
- VB.NET与C#代码在线互转的网站
- C# VB.Net代码互转 在线
- VB.NET与C#代码互相转化在线工具
- 在线工具--把C#代码转换VB.NET代码(相互转换)
- [VB.NET]点net写client程序传递参数给mssql存储过程insert,为什么要反复执行客户端代码才能成功insert,怎么才能使客户端插入记录操作变得稳定呢?
- [VB.NET]Oracle.DataAccess 连Oracle怎么老出错,try catch 打印出来的错误信息是
- [VB.NET]VB6写的DLL在vb.net中怎么调用啊 谢谢
- [VB.NET]指定的参数已超出有效值的范围 怎么解决 在线