mk_b
asked on
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.a spx?page=L ogin")
End If
'--get 12month history
If Session("MyHistoryBool") = "" Then
Dim myData As DataSet
Dim myDataTable As New DataTable("myHistory")
myDataTable.Columns.Add("m Month", GetType(String))
myDataTable.Columns.Add("A mount", GetType(Double))
myDataTable.Columns.Add("v Month", GetType(String))
myDataTable.Columns.Add("v Year", 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("DetailRecor ds").Rows( 0)("Amount ")
Dim myDataRow = myDataTable.NewRow
myDataRow("mMonth") = MonthName(yMonth) & " " & yYear
myDataRow("Amount") = myData.Tables("DetailRecor ds").Rows( 0)("Amount ")
myDataRow("vMonth") = yMonth
myDataRow("vYear") = yYear
myDataTable.Rows.Add(myDat aRow)
yMonth = yMonth - 1
Next
Dim DataHistory As New DataSet
DataHistory.Tables.Add(myD ataTable)
Session("MyHistory") = DataHistory.Tables(0).Defa ultView
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("mMont h") <> "" Then
Dim Startdate, EndDate
Dim docHeadData As New DataSet
EndDate = fDate(DateSerial(Request.Q ueryString ("mYear"), Request.QueryString("mMont h") + 1, 1 - 1))
Startdate = Request.QueryString("mMont h") & "/01/" & Request.QueryString("mYear ")
docHeadData = x.CustomerDocumentHeaders( Session("C ode"), Startdate, EndDate)
Dim myView As DataView
myView = docHeadData.Tables(1).Defa ultView
myView.Sort = "DocumentDate ASC"
pagedData.DataSource = myView
pagedData.AllowPaging = True
pagedData.PageSize = 15
Try
pagedData.CurrentPageIndex = Int32.Parse(Request.QueryS tring("Pag eNo")).ToS tring()
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
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")
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.a
End If
'--get 12month history
If Session("MyHistoryBool") = "" Then
Dim myData As DataSet
Dim myDataTable As New DataTable("myHistory")
myDataTable.Columns.Add("m
myDataTable.Columns.Add("A
myDataTable.Columns.Add("v
myDataTable.Columns.Add("v
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
Total = Total + myData.Tables("DetailRecor
Dim myDataRow = myDataTable.NewRow
myDataRow("mMonth") = MonthName(yMonth) & " " & yYear
myDataRow("Amount") = myData.Tables("DetailRecor
myDataRow("vMonth") = yMonth
myDataRow("vYear") = yYear
myDataTable.Rows.Add(myDat
yMonth = yMonth - 1
Next
Dim DataHistory As New DataSet
DataHistory.Tables.Add(myD
Session("MyHistory") = DataHistory.Tables(0).Defa
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("mMont
Dim Startdate, EndDate
Dim docHeadData As New DataSet
EndDate = fDate(DateSerial(Request.Q
Startdate = Request.QueryString("mMont
docHeadData = x.CustomerDocumentHeaders(
Dim myView As DataView
myView = docHeadData.Tables(1).Defa
myView.Sort = "DocumentDate ASC"
pagedData.DataSource = myView
pagedData.AllowPaging = True
pagedData.PageSize = 15
Try
pagedData.CurrentPageIndex
Catch ex As Exception
pagedData.CurrentPageIndex
End Try
cmdPrev.Enabled = (Not pagedData.IsFirstPage)
cmdNext.Enabled = (Not pagedData.IsLastPage)
Repeater2.DataSource = pagedData
Repeater2.DataBind()
End If
End Sub
ASKER
Its not that if you had read the question you would have seen the error is with the dataset in the Session("MyHistory")
../mk
../mk
Have you tried
dim dv as dataview = Session("MyHistory")
repeater1.datasource = dv
You're storing a dataview ( Session("MyHistory") = DataHistory.Tables(0).Defa ultView) in the session variable.
dim dv as dataview = Session("MyHistory")
repeater1.datasource = dv
You're storing a dataview ( Session("MyHistory") = DataHistory.Tables(0).Defa
ASKER
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
Else
Dim source As New DataView
source = CType(Session("MyHistory")
Repeater1.DataSource = source
Repeater1.DataBind()
End If
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
Private _dt as DataTable
Private Property dt() As DataTable
Get
If _dt Is Nothing Then _dt = Me.Page.Session("DataPage_
Return _dt
End Get
Set(ByVal Value As DataTable)
_dt = Value
Me.Page.Session("DataPage_
End Set
End Property 'dt
ASKER
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("m Month", GetType(String))
myDataTable.Columns.Add("A mount", GetType(Double))
myDataTable.Columns.Add("v Month", GetType(String))
myDataTable.Columns.Add("v Year", 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("DetailRecor ds").Rows( 0)("Amount ")
Dim myDataRow = myDataTable.NewRow
myDataRow("mMonth") = MonthName(yMonth) & " " & yYear
myDataRow("Amount") = myData.Tables("DetailRecor ds").Rows( 0)("Amount ")
myDataRow("vMonth") = yMonth
myDataRow("vYear") = yYear
myDataTable.Rows.Add(myDat aRow)
yMonth = yMonth - 1
Next
Dim DataHistory As New DataSet
DataHistory.Tables.Add(myD ataTable)
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
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("m
myDataTable.Columns.Add("A
myDataTable.Columns.Add("v
myDataTable.Columns.Add("v
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
Total = Total + myData.Tables("DetailRecor
Dim myDataRow = myDataTable.NewRow
myDataRow("mMonth") = MonthName(yMonth) & " " & yYear
myDataRow("Amount") = myData.Tables("DetailRecor
myDataRow("vMonth") = yMonth
myDataRow("vYear") = yYear
myDataTable.Rows.Add(myDat
yMonth = yMonth - 1
Next
Dim DataHistory As New DataSet
DataHistory.Tables.Add(myD
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
End Set
End Property 'dt
This line will not behave as expected... since the "day" value is 1-1=0
EndDate = fDate(DateSerial(yYear, yMonth + 1, 1 - 1))
EndDate = fDate(DateSerial(yYear, yMonth + 1, 1 - 1))
ASKER
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
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
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
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
ASKER
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?
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?
out of curiousity... if you remove the DataHistory.Clear line, whan happens?
ASKER
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("m Month", GetType(String))
myDataTable.Columns.Add("A mount", GetType(Double))
myDataTable.Columns.Add("v Month", GetType(String))
myDataTable.Columns.Add("v Year", 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("DetailRecor ds").Rows( 0)("Amount ")
Dim myDataRow = myDataTable.NewRow
myDataRow("mMonth") = MonthName(yMonth) & " " & yYear
myDataRow("Amount") = myData.Tables("DetailRecor ds").Rows( 0)("Amount ")
myDataRow("vMonth") = yMonth
myDataRow("vYear") = yYear
myDataTable.Rows.Add(myDat aRow)
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
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("m
myDataTable.Columns.Add("A
myDataTable.Columns.Add("v
myDataTable.Columns.Add("v
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
Total = Total + myData.Tables("DetailRecor
Dim myDataRow = myDataTable.NewRow
myDataRow("mMonth") = MonthName(yMonth) & " " & yYear
myDataRow("Amount") = myData.Tables("DetailRecor
myDataRow("vMonth") = yMonth
myDataRow("vYear") = yYear
myDataTable.Rows.Add(myDat
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try using IsNothing(Session("")) in place of ="".