Global.asax Problem
-
If Application("TipDate") <> Today() Then Application("TipDate") = Today() If Not IsNumeric(Application("TipNumber")) Then Application("TipNumber") = 1 Else Application("TipNumber") = Application("TipNumber") + 1 End If End If I have given the above code in the page and i want to store Application("TipNumber") and it has to increment daily depending up the Date Value. So, i have placed the Appliaction("TipNumber")=1 in Appliaction_Start of Global.asax but when ever the appliaction is running TipNumber is initialised to 1 only but not incrementing? Please help me in solving this problem
-
If Application("TipDate") <> Today() Then Application("TipDate") = Today() If Not IsNumeric(Application("TipNumber")) Then Application("TipNumber") = 1 Else Application("TipNumber") = Application("TipNumber") + 1 End If End If I have given the above code in the page and i want to store Application("TipNumber") and it has to increment daily depending up the Date Value. So, i have placed the Appliaction("TipNumber")=1 in Appliaction_Start of Global.asax but when ever the appliaction is running TipNumber is initialised to 1 only but not incrementing? Please help me in solving this problem
-
This logic probably won't work since the Application_Start event is fired only once when the application starts, Not on everyday basis.
Regards
- J O H N -
Thanks for ur reply but if i want it in daily basis how to do the coding? pls help me
-
Thanks for ur reply but if i want it in daily basis how to do the coding? pls help me
-
Thanks for ur reply but if i want it in daily basis how to do the coding? pls help me
You need to persist the value somewhere, ie a database, along with the datetime it was written. Then, perhaps in an onsession event, read this value from the database, compare the date it was written with 'todays' date, and update if necessary. If you don't persist the value, if you site ever goes down, or you modify the webconfig, or the process gets recycled for any reason, you will lose this value.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
-
Could you provide some more detail about what exactly is the requirement?
Regards
- J O H N -
Application("TipNumber") = 1 If Application("TipDate") <> Today() Then Application("TipDate") = Today() If Not IsNumeric(Application("TipNumber")) Then Application("TipNumber") = 1 Else Application("TipNumber") = Application("TipNumber") + 1 End If End If Dim cmd As SqlDataAdapter = New SqlDataAdapter("Select Thought From Thoughts_Tbl " & "Where id = " & Application("TipNumber"), Con) cmd.Fill(_dataSet, "TheTip") If _dataSet.Tables("TheTip").Rows.Count = 0 Then Application("TipNumber") = 1 cmd = New SqlDataAdapter("Select Thought From Thoughts_Tbl " & "Where id = " & Application("TipNumber"), Con) cmd.Fill(_dataSet, "TheTip") End If lbl_Title1.Text = "Thought of the Day :" lbl_ThoughtText.Text = _dataSet.Tables("TheTip").Rows(0).Item("Thought") This is the actual code where i'm check the date with today's day if it matches and the TipNumber is not numeric it wil take first statement Application("TipNumber") = 1 or if TipNumber is numeric i.e having some number, it wil be incremented in else part Application("TipNumber") = Application("TipNumber") + 1 but TipNumber which is incrementing is not saving? Now how to save TipNumber n incrementing it and get the next "TipOfDay" from database? Pls help me with some solution
-
Application("TipNumber") = 1 If Application("TipDate") <> Today() Then Application("TipDate") = Today() If Not IsNumeric(Application("TipNumber")) Then Application("TipNumber") = 1 Else Application("TipNumber") = Application("TipNumber") + 1 End If End If Dim cmd As SqlDataAdapter = New SqlDataAdapter("Select Thought From Thoughts_Tbl " & "Where id = " & Application("TipNumber"), Con) cmd.Fill(_dataSet, "TheTip") If _dataSet.Tables("TheTip").Rows.Count = 0 Then Application("TipNumber") = 1 cmd = New SqlDataAdapter("Select Thought From Thoughts_Tbl " & "Where id = " & Application("TipNumber"), Con) cmd.Fill(_dataSet, "TheTip") End If lbl_Title1.Text = "Thought of the Day :" lbl_ThoughtText.Text = _dataSet.Tables("TheTip").Rows(0).Item("Thought") This is the actual code where i'm check the date with today's day if it matches and the TipNumber is not numeric it wil take first statement Application("TipNumber") = 1 or if TipNumber is numeric i.e having some number, it wil be incremented in else part Application("TipNumber") = Application("TipNumber") + 1 but TipNumber which is incrementing is not saving? Now how to save TipNumber n incrementing it and get the next "TipOfDay" from database? Pls help me with some solution
Having this Data in the Application Variable is pointless. Application_Start Event is not meant for this. This will not serve your purpose. Why don't you have a Date Column to the Thought's Table and fetch the Tip based on the Date. I think this would be the appropriate solution to the given problem.
Regards
- J O H N -