Session and Dataview issue

Ok please can someone help me with this anouying little problem. As you can se from the code below th my page loads the first time and it runs the If Session("MyHistoryBool") = "" Then and it works and shows the history fine. i and now have a dataset saved to Session("MyHistory") and session("MyHistoryBool") = True.

i would then click in a link and it would run the page again and then skip to the Else of If Session("login") <> "True"
but it will not show the data properly from the Session("MyHistory") ? i have also tryed using cType(Session("MyHistory") , Dataview)

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Session("login") <> "True" Then
            Response.Redirect("login.aspx?page=Login")
        End If
        '--get 12month history
        If Session("MyHistoryBool") = "" Then
            Dim myData As DataSet
            Dim myDataTable As New DataTable("myHistory")
            myDataTable.Columns.Add("mMonth", GetType(String))
            myDataTable.Columns.Add("Amount", GetType(Double))
            myDataTable.Columns.Add("vMonth", GetType(String))
            myDataTable.Columns.Add("vYear", GetType(String))
            Dim Startdate, EndDate

            Dim i, cCount As Integer
            Dim yYear, yMonth As Integer
            yYear = Year(Now())
            yMonth = Month(Now())
            For i = 1 To 12

                If yMonth = 0 Then
                    yYear = yYear - 1
                    yMonth = 12
                Else
                End If
                EndDate = fDate(DateSerial(yYear, yMonth + 1, 1 - 1))
                Startdate = yMonth & "/01/" & yYear
                myData = x.CustomerTurnover(Session("Code"), Startdate, EndDate)

                Total = Total + myData.Tables("DetailRecords").Rows(0)("Amount")
                Dim myDataRow = myDataTable.NewRow
                myDataRow("mMonth") = MonthName(yMonth) & " " & yYear
                myDataRow("Amount") = myData.Tables("DetailRecords").Rows(0)("Amount")
                myDataRow("vMonth") = yMonth
                myDataRow("vYear") = yYear
                myDataTable.Rows.Add(myDataRow)

                yMonth = yMonth - 1
            Next

            Dim DataHistory As New DataSet
            DataHistory.Tables.Add(myDataTable)

            Session("MyHistory") = DataHistory.Tables(0).DefaultView
            Repeater1.DataSource = Session("MyHistory")
            Repeater1.DataBind()

            myDataTable.Clear()
            myData.Clear()

            Session("MyHistoryBool") = "True"
            Session("Total") = Total
        Else
            Repeater1.DataSource = Session("MyHistory")
            Repeater1.DataBind()
        End If

        '--get selected month history
        If Request.QueryString("mMonth") <> "" Then
            Dim Startdate, EndDate
            Dim docHeadData As New DataSet
            EndDate = fDate(DateSerial(Request.QueryString("mYear"), Request.QueryString("mMonth") + 1, 1 - 1))
            Startdate = Request.QueryString("mMonth") & "/01/" & Request.QueryString("mYear")
            docHeadData = x.CustomerDocumentHeaders(Session("Code"), Startdate, EndDate)

            Dim myView As DataView
            myView = docHeadData.Tables(1).DefaultView
            myView.Sort = "DocumentDate ASC"

            pagedData.DataSource = myView
            pagedData.AllowPaging = True
            pagedData.PageSize = 15

            Try
                pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("PageNo")).ToString()
            Catch ex As Exception
                pagedData.CurrentPageIndex = 0
            End Try

            cmdPrev.Enabled = (Not pagedData.IsFirstPage)
            cmdNext.Enabled = (Not pagedData.IsLastPage)

            Repeater2.DataSource = pagedData
            Repeater2.DataBind()
        End If


    End Sub
LVL 5
mk_bAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeff CertainCommented:
Is the Session("login" storing a boolean or a string? If a boolean, it will never = "True"

Try using IsNothing(Session("")) in place of ="".
0
mk_bAuthor Commented:
Its not that if you had read the question you would have seen the error is with the dataset in the Session("MyHistory")

../mk
0
Jeff CertainCommented:
Have you tried
dim dv as dataview = Session("MyHistory")
repeater1.datasource = dv

You're storing a dataview ( Session("MyHistory") = DataHistory.Tables(0).DefaultView) in the session variable.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

mk_bAuthor Commented:
Yes currently i have it like this but still not working?

Else
            Dim source As New DataView
            source = CType(Session("MyHistory"), DataView)
            Repeater1.DataSource = source
            Repeater1.DataBind()
End If

0
Jeff CertainCommented:
Okay... here is some code from a working project. I use a datatable, not a dataview, but the concept is the same... Instead of merely using the session object, I've used a property to reference the datatable. I initialize the dt property once, during the Initialize event for the control.

  Private _dt as DataTable
  Private Property dt() As DataTable
    Get
      If _dt Is Nothing Then _dt = Me.Page.Session("DataPage_dt")
      Return _dt
    End Get
    Set(ByVal Value As DataTable)
      _dt = Value
      Me.Page.Session("DataPage_dt") = _dt
    End Set
  End Property 'dt
0
mk_bAuthor Commented:
Still not its strang i step though the code and it looks like its working but when you get though it no data?

here is what i have now

        '--get 12month history
        If Session("MyHistoryBool") = "" Then
            Dim myData As DataSet
            Dim myDataTable As New DataTable("myHistory")
            myDataTable.Columns.Add("mMonth", GetType(String))
            myDataTable.Columns.Add("Amount", GetType(Double))
            myDataTable.Columns.Add("vMonth", GetType(String))
            myDataTable.Columns.Add("vYear", GetType(String))
            Dim Startdate, EndDate

            Dim i, cCount As Integer
            Dim yYear, yMonth As Integer
            yYear = Year(Now())
            yMonth = Month(Now())
            For i = 1 To 12

                If yMonth = 0 Then
                    yYear = yYear - 1
                    yMonth = 12
                Else
                End If
                EndDate = fDate(DateSerial(yYear, yMonth + 1, 1 - 1))
                Startdate = yMonth & "/01/" & yYear
                myData = x.CustomerTurnover(Session("CustCode"), Startdate, EndDate)

                Total = Total + myData.Tables("DetailRecords").Rows(0)("Amount")
                Dim myDataRow = myDataTable.NewRow
                myDataRow("mMonth") = MonthName(yMonth) & " " & yYear
                myDataRow("Amount") = myData.Tables("DetailRecords").Rows(0)("Amount")
                myDataRow("vMonth") = yMonth
                myDataRow("vYear") = yYear
                myDataTable.Rows.Add(myDataRow)

                yMonth = yMonth - 1
            Next

            Dim DataHistory As New DataSet
            DataHistory.Tables.Add(myDataTable)

            Me.dt = DataHistory.Tables(0)

            Repeater1.DataSource = Me.dt
            Repeater1.DataBind()

            DataHistory.Clear()
            myDataTable.Clear()
            myData.Clear()

            Session("MyHistoryBool") = "True"
            Session("Total") = Total
        Else
            Repeater1.DataSource = Me.dt
            Repeater1.DataBind()
        End If

    Private _dt As DataTable
    Private Property dt() As DataTable
        Get
            If _dt Is Nothing Then _dt = Me.Page.Session("MyHistory")
            Return _dt
        End Get
        Set(ByVal Value As DataTable)
            _dt = Value
            Me.Page.Session("MyHistory") = _dt
        End Set
    End Property 'dt
0
Jeff CertainCommented:
This line will not behave as expected... since the "day" value is 1-1=0

EndDate = fDate(DateSerial(yYear, yMonth + 1, 1 - 1))
0
mk_bAuthor Commented:
no that day value will be the last day of the month!

the thing that gets me is that it works the first time arround its just when you try get the datatable from the session or now dt property it displays nothing???

../mk
0
Jeff CertainCommented:
Okay... when I pulled up the code, it indicated that value had to range from 1 to 31...

I wonder if what is happening is that the datatable is being passed with an implied dependency on the parent dataset?

Try changing Me.dt = DataHistory.Tables(0) to me.dt=mydatatable
0
mk_bAuthor Commented:
still not Chaosian i dont htink its going to be something like that? like i've said it works the first time just not there after?

and whin i step thought the code all look well it says Me.dt is a datatable but then when you out there is no data?
0
Jeff CertainCommented:
out of curiousity... if you remove the DataHistory.Clear line, whan happens?
0
mk_bAuthor Commented:
VICTORY

I used the httpcache

http://www.codeproject.com/aspnet/datastorage.asp
http://samples.gotdotnet.com/quickstart/aspplus/doc/datacaching.aspx


        Dim Source As DataTable
        Source = Cache("MyDataSet")

        If Source Is Nothing Then

            Dim myData As DataSet
            Dim myDataTable As New DataTable("myHistory")
            myDataTable.Columns.Add("mMonth", GetType(String))
            myDataTable.Columns.Add("Amount", GetType(Double))
            myDataTable.Columns.Add("vMonth", GetType(String))
            myDataTable.Columns.Add("vYear", GetType(String))
            Dim Startdate, EndDate

            Dim i, cCount As Integer
            Dim yYear, yMonth As Integer
            yYear = Year(Now())
            yMonth = Month(Now())
            For i = 1 To 12

                If yMonth = 0 Then
                    yYear = yYear - 1
                    yMonth = 12
                Else
                End If
                EndDate = fDate(DateSerial(yYear, yMonth + 1, 1 - 1))
                Startdate = yMonth & "/01/" & yYear
                myData = x.CustomerTurnover(Session("CustCode"), Startdate, EndDate)

                Total = Total + myData.Tables("DetailRecords").Rows(0)("Amount")
                Dim myDataRow = myDataTable.NewRow
                myDataRow("mMonth") = MonthName(yMonth) & " " & yYear
                myDataRow("Amount") = myData.Tables("DetailRecords").Rows(0)("Amount")
                myDataRow("vMonth") = yMonth
                myDataRow("vYear") = yYear
                myDataTable.Rows.Add(myDataRow)

                yMonth = yMonth - 1
            Next

            Source = myDataTable
            Cache("MyDataSet") = Source

            Cache("MyTotal")= Total

        End If

        Repeater1.DataSource = Source
        Repeater1.DataBind()


Thanks for trying Chaosian. I think it may have had something to do with DataHistory.Clear() myDataTable.Clear() myData.Clear()/ maybe....

im going to ask the the questing be closed and points refunded?

regards,
../mk
0
ee_ai_constructCommented:
Question answered by asker or dialog valuable.
Closed, 125 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.