แก้เป็น อย่างงี้ก็ไม่หายค่ะ
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>")
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)
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
ก็งงเหมือนกันค่ะ ทำไงดี ทดลอง เอาค่า label lblExpireDate.Text มาใช้ในหน้า DetailPackage.aspx .... เวลากดปุ่มซื้อ มันก็ Error อย่างงี้ อีก Conversion from string "31/03/2012" to type 'Date' is not valid. ตามที่โพสต์ข้างบนครั้งแรกอ่ะค่ะ