Results 1 to 2 of 2

Thread: I have problem in Date format in C# .NET 1.1

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Posts
    28

    I have problem in Date format in C# .NET 1.1

    HI ALL,

    My .NET application devloped in C# used mainly class file (OOAD) and user controls etc and it is desktop application not web based application. Database is SQL server 2000.

    Now I have problem in Date format.

    Scenario is :
    If my application is running in the following setup, i.e The SQL server2000 is installed with DDMMY format and system setting also DDMMYY.
    Now when the user enters the date like 19-04-2007 in the UI,it is generating error (Erro msg is : The conversion of char dat type to smalldatetime data type resulted in an out of range small datetime value.)

    BUT If the PC set up is in MMDDYY format and SQL server too then no problem. i.e Application will allow/Fetch the record when the user enter date like 19-04-2007.

    Brief about Architecture: My Application has four tier architecture. i.e Presentation, Business Facade (Remoting used here to call Business service), Business service (BS), Datatransfer.

    This .NET application is generalised application,Means it is not for any specific country. So I need best way to fix this problem.

    Please help me out to solve this problem.Thank you so much....


    Thanks
    Radhakrishnan.R

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: I have problem in Date format in C# .NET 1.1

    The best way to fix it is to not try to put text data into date columns in the database and rely on the database to convert it for you. If you are putting data into a date column then you should be putting date objects, NOT text. If the user is inputting the data into a TextBox then the responsibility falls on YOU to validate and convert that text to a date object. The sensible option is to use a DateTimePicker, which handles the validation and conversion for you. Its Value property returns a DateTime object that you can save to the database without possibility of issue.

    Remember: just because a string contains some numbers that represent a date doesn't make it a date. It's a string representation of a date. A database stores dates in a date column, not string representations of them.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width