[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 551
  • Last Modified:

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
0
mk_b
Asked:
mk_b
  • 6
  • 6
1 Solution
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now