3

I have a textbox with value that stores ValidFrom form value:

31.01.2012

and cultures set to:

<globalization culture="en-GB" uiCulture="en-GB"/>

in web.config.

And now, ObjectDataSource update method:

    public static void UpdateLac(int id, DateTime ValidFrom)
    {
        /// ...
    }

fails as I get exception that string cannot be parsed. However date in format dd.mm.yyyy (31.01.2012) is valid en-GB format and can be parsed (as far as I know). I have tested it with following code:

            DateTimeFormatInfo dtfi = CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat;
            var date = DateTime.Parse("31.01.2012", dtfi);
            Console.Write(date.ToLongDateString());

So how come that ObjectDataSource internal conversion fails to convert string (31.01.2012) to DateTime in this example?

dragonfly
  • 17,407
  • 30
  • 110
  • 219
  • just try 01.31.2012 and see whether its working or not – Satinder singh Jul 02 '12 at 13:04
  • 01.31.2012 gets converted to DateTime by ObjectDataSource, but 01.31.2012 is not converted when I call (just to test) DateTime.Parse("01.31.2012") inside postback (as my culture is set to en-GB) – dragonfly Jul 02 '12 at 13:09
  • Can object type is the ODS working with? If it is a custom type, can you provide the source code for it's properties and fields? – Jeff Jul 02 '12 at 13:15
  • set format as dd.MM.yyyy hope its works – Satinder singh Jul 02 '12 at 13:18
  • @Jeff : ObjectDataSource do not work with custom type. It calls UpdateMethod and passes .NET built in types (string, int, DateTime etc) – dragonfly Jul 02 '12 at 13:21
  • @satinder singh: thanks. but why should I change date format (and where)? Date format is not the issue, as it's parsed correctly throughout the web app unless ObjectDataSource tries to parse it. – dragonfly Jul 02 '12 at 13:23
  • @dragonfly That's not true. I have used it with custom types before. – Jeff Jul 02 '12 at 14:00
  • @Jeff - "ObjectDataSource do not work with custom type" - I ment that in my example ObjectDataSource do not uses custom type, but .NET types :) – dragonfly Jul 02 '12 at 16:47

1 Answers1

0

As far as I know the culture info is loaded directly from the OS ( in this case windows), you can check on your regional setting for the format specified. This is a screenshot from my pc:

http://imageshack.us/photo/my-images/96/engbg.png/

As you can see the format for short date is: dd/MM/aa, so maybe there is something going on with your server regional settings or the input should be: 31/01/12 instead of 31.01.2012

Hope this helps.

zaiboot
  • 131
  • 5