Cast from string "27-06-2008" to type 'Date' is not valid
I have a major problem, I have a working Asp.NET application running in Win2003. This setup is working perfectly without any probelm.
Now I have a new server with Win2003 R2 SP2 and I installed my asp application to this server and now I getting following error in all the pages which are having date fields. Eventhough I enter "27/06/2008" it gives me following error
Cast from string "27/06/2008" 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: Cast from string "27/06/2008" to type 'Date' is not valid.
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.
[InvalidCastException: Cast from string "27/06/2008" to type 'Date' is not valid.]
Microsoft.VisualBasic.CompilerServices.DateType.FromString(String Value, CultureInfo culture) +162
Microsoft.VisualBasic.CompilerServices.DateType.FromString(String Value) +53
Microsoft.VisualBasic.CompilerServices.DateType.FromObject(Object Value) +156
SharjahVisa.SearchList.Page_Load(Object sender, EventArgs e) +526
System.Web.UI.Control.OnLoad(EventArgs e) +67
Version Information: Microsoft .NET Framework Version:1.1.4322.2379; ASP.NET Version:1.1.4322.2379
All my three servers are set to dd/MM/yyyy format in reginal settings with Indonesia as country. But the same application working fine in other server (same configuration).
I've tried to set the date setting in regional setting to MM/dd/yyyy and I get the same error.
This there any setting in OS, IIS or ASP.NET I should set to fix this problem?
Which data type have u declared? Is it DateTime? Please give a sample code. So that I can check it out for you.
Dim dTgl AS Date
dTgl = txtTgl.Text 'txtTgl is a textbox, this is the line that trigger the error.
It is ok if I enter the date as "06/27/2008" but this is not the format we use here.
As I mention above that this does not cause any problem in my old server. So I think there must be something in the OS or IIS setting.
Are you using ASP.NET 2.0 or earlier version? If you are using 2.0, then there is no class called Date. It is DateTime only.
gokild: kslchiang is using Visual Basic, which does have a Date data type.
kslchiang: I am not able to reproduce the behavior you describe. My system's date format is set to M/d/yyyy; if I run the following code, I get the error you describe:
Dim dTgl AS Date = "27/06/2008"
If I change my system's date format to d/M/yyyy, the code runs without error. Have you tried doing an iisreset or rebooting after changing your system's date format?
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
Gokild : I am using VS 2003 SP1, ASP.NET 1.1 and as Phil said that is VB code (code behind).
Phil : iisreset ? you mean stop the iis dan run again?
Not yet, but I have restart the server.
Last edited by kslchiang; 06-28-2008 at 01:05 PM.
By athomas42 in forum .NET
Last Post: 06-25-2007, 04:54 PM
By Marcos in forum VB Classic
Last Post: 01-25-2006, 11:18 AM
Last Post: 10-02-2005, 11:57 PM
By mdengler in forum ASP.NET
Last Post: 11-26-2002, 02:32 PM
By Chandra in forum VB Classic
Last Post: 06-22-2000, 07:30 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center