 |
|
โปรแกรมรันบนเครื่องตัวเองได้ แต่รันบนโฮสต์แล้ว error เกี่ยวกับ date |
|
 |
|
|
 |
 |
|
ช่วยด้วยค่ะ ปัญหาโลกแตก
โปรแกรมรันบนเครื่องตัวเองได้ แต่รันบนโฮสต์แล้ว error (error ตรงโค้ดสีแดงอ่ะค่ะ)
แก้เป็น อย่างงี้ก็ไม่หายค่ะ
Dim i As Integer = DateTime.Compare( CDate(lblExpireDate.Text) , dTodayDate )
+++++++++++++++++++++++++++++++++++++++
Code ที่กำลัง Error ดังนี้ค่ะ
Private Sub btnBuy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuy.Click
Dim dTodayDate As Date = System.DateTime.Today
Dim i As Integer = DateTime.Compare(CType(lblExpireDate.Text, Date), dTodayDate)
If i > 0 Then
' dExpireDate is Greater than dTodayDate = เปิดขายอยู่
Response.Redirect("BuyPackage.aspx?pPackageId=" & lblPackageId.Text)
ElseIf i = 0 Then
' dExpireDate is Less than dTodayDate = หมดอายุแล้ว
Page.RegisterClientScriptBlock("OnLoad", "<script>alert('โปรโมชั่นนี้หมดเขตแล้ว (ปิดการขายแล้ว)')</script>")
ElseIf i < 0 Then
' dExpireDate is Less than dTodayDate = หมดอายุแล้ว
Page.RegisterClientScriptBlock("OnLoad", "<script>alert('โปรโมชั่นนี้หมดเขตแล้ว (ปิดการขายแล้ว)')</script>")
End If
End Sub
+++++++++++++++++++++++++++++++++++++++
หน้าเว็บกดปุ่มซื้อ แล้ว Error ดังนี้ค่ะ
Server Error in '/' Application.
--------------------------------------------------------------------------------
Conversion from string "31/03/2012" to type 'Date' is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Conversion from string "31/03/2012" to type 'Date' is not valid.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidCastException: Conversion from string "31/03/2012" to type 'Date' is not valid.]
Microsoft.VisualBasic.CompilerServices.DateType.FromString(String Value, CultureInfo culture) +341820
Microsoft.VisualBasic.CompilerServices.DateType.FromString(String Value) +32
Prosogo.DetailPackage.btnBuy_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\Prosogo\DetailPackage.aspx.vb:158
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Tag : .NET, Ms Access, Web (ASP.NET), VB.NET, VS 2003 (.NET 1.1)
|
|
 |
 |
 |
 |
Date :
2012-02-21 11:37:03 |
By :
หมู |
View :
1169 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบอกเพิ่มเติมหน่อยค่ะ
มีอีกหน้า ก็ Error แบบนี้ แล้วแก้หาย (หน้า OldDetailPackage.aspx)
แต่เอาไปใช้กับ หน้าเว็บอีกหน้านึงข้างบน (หน้า DetailPackage.aspx) ไม่ได้ค่ะ มัน Error
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'..... Select data from table
Dim dExpireDate As Date
dExpireDate = dbread.Item("ExpireDate").ToString
lblExpireDate.Text = dExpireDate.ToString("dd/MM/yyyy")
....
dbread.Close()
dbconn.Close()
Dim dTodayDate As Date = System.DateTime.Today
Dim i As Integer = DateTime.Compare(dExpireDate, dTodayDate)
If i > 0 Then
' dExpireDate is Greater than dTodayDate = ยังไม่หมดอายุ
spanClose.InnerHtml = "กำลังเปิดขายอยู่"
Page.RegisterClientScriptBlock("OnLoad", "<script>alert('โปรโมชั่นนี้กำลังเปิดขายอยู่ ซื้อ ไปที่เมนูโปรชั่นปัจจุบัน')</script>")
End If
End Sub
++++++++++++++++++++++++
ที่หน้า DetailPackage.aspx ใช้แบบนี้ไม่ได้ เพราะว่า ตอนรัน ค่า dExpireDate มันเป็น Nothing อ่ะค่ะ เหมือนว่าค่ามันหายไป
ไม่รู้ทำไมหายไป อาจเป็นเพราะว่า ในหน้า Detail...aspx ค่า dExpireDate มันอยู่ใน Page_Load .... แล้วเราจะเอาค่า dExpireDAte มาใช้อีกทีตอนกดปุ่มซื้อ ซึ่ง PageLoad มัน End Sub ไปแล้วมันเลยหายไปรึป่าว......แต่หายไปทั้งๆที่ ประกาศตัวแปร dExpireDate ไว้นอก PageLoad แล้วอ่ะคะ
ก็งงเหมือนกันค่ะ ทำไงดี ทดลอง เอาค่า label lblExpireDate.Text มาใช้ในหน้า DetailPackage.aspx .... เวลากดปุ่มซื้อ มันก็ Error อย่างงี้ อีก Conversion from string "31/03/2012" to type 'Date' is not valid. ตามที่โพสต์ข้างบนครั้งแรกอ่ะค่ะ
หรือมันเกี่ยวกับ set web.config คะ เพราะเอา Error นี้ไปค้นหาในกูเกิลก็เจออันนี้ค่ะ http://stackoverflow.com/questions/7945310/conversion-from-string-31-03-2012-to-type-date-is-not-valid
แต่อ่านแล้วไม่รู้จะ Set Culture เป็นอะไร ....ปล.Host เค้าบอกว่าเครื่องเค้ามีระบบเวลาเป็น ค.ศ.
|
 |
 |
 |
 |
Date :
2012-02-21 12:11:40 |
By :
หมู |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|