Last post Jan 26, 2010 11:34 PM by SEFL
Jan 26, 2010 07:02 PM|SEFL|LINK
This one has me completely confused. I'm using the function below in a .vb file (it's the only function in the file as of right now).
Public Shared Function GenerateOrderID(ByVal Required As Boolean) As Integer
Dim Final_ID As Integer = 0
Dim Cookie_Value As String = Current.Request.Cookies("OUI").Value
GenerateOrderID = 0
If IsNumeric(Cookie_Value) Then Final_ID = Convert.ToInt32(Cookie_Value)
If Final_ID = 0 And Required Then
Dim SQL_Query As String = "Insert into Orders (Subtotal) values (0)"
Final_ID = Convert.ToInt32(Data.RetrieveSingleValue("Max (Order_ID) as Order_ID", "Orders", "", "0"))
Current.Response.Cookies("OUI").Value = Final_ID
Dim Cur_Date As Date = DateTime.Now
Dim One_Week_Ahead As Date = DateAdd("d", 7, Cur_Date)
Current.Response.Cookies("OUI").Expires = One_Week_Ahead
GenerateOrderID = Final_ID
Now, when I run it locally on my machine (uncompiled), it runs fine. No errors whatsoever. But when I upload it, I get a nullreferenceexception from it.
[NullReferenceException: Object reference not set to an instance of an object.]
Orders.GenerateOrderID(Boolean Required) +67
add_to_cart.Page_Load(Object Source, EventArgs E) +47
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
This really doesn't make sense to me, given that I set GenerateOrderID to 0 in the very beginning. (I also put Final_ID and assigned a 0 value to it in semi-desperation.)
Could someone please explain to me where the nullreferenceexception could occur? Thanks.
Jan 26, 2010 09:58 PM|mbanavige|LINK
if there is no OUI cookie, then that error would occur when you try to get the value from a cookie that is null.
Jan 26, 2010 11:34 PM|SEFL|LINK
Oh for crying out loud. I don't know whether to be happy and thank you or hate you completely for making me feel so stupid for missing something so simple. So I'll just give you one of those "Mark as Right Answer" things and my gratitude. Much appreciated.