Unable to retrieve dataset from the session

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • whidbey
    New Member
    • Feb 2007
    • 7

    Unable to retrieve dataset from the session

    Hello friends, I am whidbey, new to thescripts and dot net as well.I am working over Online Shopping Cart,web application.I design a page (webform5.aspx) where user search books then select the books to buy from the datagrid.
    User can select books using checkboxes in the datagrid.

    The selected books are stored in a session variable name session("temp") which is a dataset type.After storing dataset in session (in bold letters),user will redirected to next page "webform6.aspx" . Here is the code....

    Code:
    sub button2_click(sender as object,e as eventargs)
      'con.close()
      dim da as sqldataadapter,ds as dataset
      dim con as sqlconnection
      dim griditem as datagriditem
      dim kk as boolean
      dim row as integer
        con=new sqlconnection("server=WADHWA;user id=sa;pwd=;initial catalog=OnlineShoppingDatabase")
              con.open()
              da=new SqlDataAdapter()
              da.selectcommand=new SqlCommand()
              da.selectcommand.connection=con
    		  da.selectcommand.commandtext="insert temp_info values(@BookId,@CatId,@Title,@Author,@Publisher,@Price,@Quantity)"
    		  da.selectcommand.parameters.add(new sqlparameter("@BookId",SqlDbType.Int,0,"BookId"))
    		  da.selectcommand.parameters.add(new sqlparameter("@CatId",SqlDbType.Int,0,"CatId"))
    		  da.selectcommand.parameters.add(new sqlparameter("@Title",SqlDbType.varchar,10,"Title"))
    		  da.selectcommand.parameters.add(new sqlparameter("@Author",SqlDbType.varchar,10,"Author"))
    		  da.selectcommand.parameters.add(new sqlparameter("@Publisher",SqlDbType.varchar,10,"Publisher"))
    		  da.selectcommand.parameters.add(new sqlparameter("@Price",SqlDbType.float,0,"Price"))
    		  da.selectcommand.parameters.add(new sqlparameter("@Quantity",SqlDbType.Int,0,"Quantity"))
    		  
              
      for each griditem in datagrid1.items
       'chk=griditem.cells(0).findcontrol("checkbox")
       'kk=directcast(griditem.Cells(1).Controls(0), CheckBox).checked
    da.selectcommand.parameters("@BookId").value=integer.parse(griditem.cells(8).text)
    		  da.selectcommand.parameters("@CatId").value=integer.parse(griditem.cells(9).text)
    		  da.selectcommand.parameters("@Title").value=griditem.cells(2).text
    		  da.selectcommand.parameters("@Author").value=griditem.cells(3).text
    		  da.selectcommand.parameters("@Publisher").value=griditem.cells(4).text
    		  da.selectcommand.parameters("@Price").value=decimal.parse(griditem.cells(5).text.Replace(" ", ""), Globalization.NumberStyles.AllowThousands or Globalization.NumberStyles.AllowCurrencySymbol or Globalization.NumberStyles.AllowDecimalPoint)
    		  da.selectcommand.parameters("@Quantity").value=integer.parse(griditem.cells(6).text)    
       kk=directcast(griditem.cells(0).findcontrol("checkbox1"),checkbox).checked
        if kk then
              'response.write("checked")
          row =da.selectcommand.executenonquery()
         end if
         row=0
        next  
         [B]ds=new DataSet
        da.fill(ds,"temp_info")
        session("temp")=ds[/B]    
        'ds = nothing
        'da=nothing
        con.close()
        response.redirect("webform6.aspx")
      end sub

    Then, I retrieve this dataset on the page load event of "webform6.aspx" .Here is the code.....

    Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            'If Not Page.IsPostBack Then
            If Session("temp") Is Nothing Then
                ds = New DataSet
                da = New SqlDataAdapter
                con = New SqlConnection("server=WADHWA;user id=sa;pwd=;initial catalog=onlineshoppingdatabase")
                con.Open()
                da.SelectCommand = New SqlCommand("select * from temp_info", con)
                da.Fill(ds, "temp_info")
                'DataGrid1.DataSource = ds
                'DataGrid1.DataSource = ds.Tables("temp_info")
                DataGrid1.DataBind()
            End If
            If Not Page.IsPostBack Then
                'DataGrid1.EnableViewState = False
                ds = New DataSet
                ds = CType(Session("temp"), DataSet)
                DataGrid1.DataSource = ds
                DataGrid1.DataBind()
            End If
        End Sub
    But, I got an error :

    Exception Details: System.Web.Http Exception: The IListSource does not contain any data sources.

    But, I got an error :

    Exception Details: System.Web.Http Exception: The IListSource does not contain any data sources.

    Help me to remove this error and give me some good knowledge on this issue
    Last edited by kenobewan; Feb 22 '07, 12:08 AM. Reason: Add code tags
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Welcome to the site. Where do you use IListSource?

    Please use code tags (# icon) as it makes your code easier to read. Thanks.

    Comment

    Working...