DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2007

    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.

    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: 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
    System.Web.UI.Control.LoadRecursive() +35
    System.Web.UI.Page.ProcessRequestMain() +750


    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?


  2. #2
    Join Date
    Jun 2008
    Which data type have u declared? Is it DateTime? Please give a sample code. So that I can check it out for you.

  3. #3
    Join Date
    Oct 2007
    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.


  4. #4
    Join Date
    Jun 2008
    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.

  5. #5
    Join Date
    Nov 2003
    Portland, OR
    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?
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  6. #6
    Join Date
    Oct 2007
    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.

Similar Threads

  1. Submitting Infopath to a .net Web Service
    By athomas42 in forum .NET
    Replies: 1
    Last Post: 06-25-2007, 04:54 PM
  2. Packed Data(Comp-3, etc)
    By Marcos in forum VB Classic
    Replies: 3
    Last Post: 01-25-2006, 11:18 AM
  3. Replies: 3
    Last Post: 10-02-2005, 11:57 PM
  4. Input string was not in a correct format
    By mdengler in forum ASP.NET
    Replies: 0
    Last Post: 11-26-2002, 02:32 PM
  5. Replies: 0
    Last Post: 06-22-2000, 07:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.