Session传值的问题
把一个Cart(维护一个DataSet)对象从第一个页面传到第二个页面,然后用DataList绑定
第一个页面
private cart as new Cart
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cart = New Cart
HttpContext.Current.Session( "CART ") = cart
End Sub
第二个页面
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cart As New Cart
cart = CType(HttpContext.Current.Session( "CART "), BLL.Cart)
DataList1.DataSource = cart.GetCart()
DataList1.DataBind()
End Sub
cart对象的定义
Public Class Cart
Private ds As DataSet
Private table As DataTable
Public Sub New()
ds = New DataSet
table = ds.Tables.Add( "cartInfo ")
Dim column As DataColumn
column = New DataColumn
column.ColumnName = "itemId "
column.DataType = System.Type.GetType( "System.String ")
table.Columns.Add(column)
column = New DataColumn
column.ColumnName = "itemName "
column.DataType = System.Type.GetType( "System.String ")
table.Columns.Add(column)
column = New DataColumn
column.ColumnName = "quantity "
column.DataType = System.Type.GetType( "System.String ")
table.Columns.Add(column)
column = New DataColumn
column.ColumnName = "unitPrice "
column.DataType = System.Type.GetType( "System.String ")
table.Columns.Add(column)
End Sub
Public Sub Add(ByVal itemId As String, ByVal itemName As String, ByVal quantity As String, ByVal unitPrice As String)
Dim row As DataRow = ds.Tables( "cartInfo ").NewRow
row( "itemId ") = itemId
row( "itemName ") = itemName
row( "quantity ") = quantity
row( "unitPrice ") = unitPrice
End Sub
Public Function GetCart() As DataSet
Return ds
End Function
End Class
错误:未将对象引用设置到对象实例
错在哪里了
[解决办法]
是那里的
错误:未将对象引用设置到对象实例
造成的阿?
不过vb不行啊。。。
[解决办法]
虽然VB不是太好..你总得把错误的地方贴出来吧,这样好分析...VB太不熟了..
[解决办法]
没有在Global文件下没有声明Session( "CART ")