我用 session 和GridView控件做了一个简单的购物车,可以装商品了,但是为什么只能买一件东西呢,问题出在哪里啊,请教各位大侠....
需要贴代码吗...

解决方案 »

  1.   

    自己顶上..
    代码;
     Sub AddToTable(ByVal bookid As String)
            Dim adp As OleDbDataAdapter
            Dim ds As DataSet
            Dim Sql As String
            Sql = "select * from book where bookid=" & bookid
            Dim db As New ConnDB
            Dim conn As OleDbConnection = db.Getcn
            adp = New OleDbDataAdapter(Sql, conn)
            Dim dt As DataTable 
             ds = New DataSet()        
             adp.Fill(ds, "book")
            dt = ds.Tables("book")
            Dim dr As DataRow = mytb.NewRow()
            dr(0) = dt.Rows(0)("bookid") 
             dr(1) = dt.Rows(0)("bookname")
            dr(2) = dt.Rows(0)("price")
            dr(3) = 1
            dr(4) = dr(2) * dr(3)
            mytb.Rows.Add(dr)
        End Sub
          Sub newTable()
            mytb = New DataTable()
            mytb.Columns.Add(New DataColumn("bookid", GetType(String)))
            mytb.Columns.Add(New DataColumn("bookname", GetType(String)))
            mytb.Columns.Add(New DataColumn("bookprice", GetType(System.Int32)))
            mytb.Columns.Add(New DataColumn("bookcount", GetType(System.Int32)))
            mytb.Columns.Add(New DataColumn("booktotal", GetType(System.Int32)))
        End Sub
       Sub Total()
            Dim i As Integer
            Dim booktotal As Integer = 0
            Dim bookcount As Integer = 0
            For i = 0 To mytb.Rows.Count - 1
                booktotal = booktotal + mytb.Rows(i)(4)
                bookcount = bookcount + mytb.Rows(i)(3)
            Next
            lbltatol.Text = " 总金额:" & booktotal
            lblcount.Text = "商品总数量:" & bookcount
        End Sub
         Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim bookid As String = Request.QueryString("id")
            If Session("boodcart") Is Nothing Then
                newTable()
                Session("bookcart") = mytb
            Else
                mytb = Session("bookcart")
            End If        If Not Page.IsPostBack Then
                If (Not bookid = "") Then
                    Call AddToTable(bookid)
                End If
                Call Total()
                GridView1.DataSource = New DataView(mytb)
                GridView1.DataBind()
            End If
        End Sub
    大概就这些了``运行调试总是只能买一件商品....为什么啊....要是不得,明天再解决..学校准备要关灯了
      

  2.   

            If Session("boodcart") Is Nothing Then 
                newTable() 
                Session("bookcart") = mytb 
            Else 
                mytb = Session("bookcart") 
            End If 低级错误,赫赫,结贴把