the safest way of handling datetime between asp.net and ms sql

Discussion in 'ASP .Net' started by H5N1, Oct 9, 2006.

  1. H5N1

    H5N1 Guest

    Hi there

    I know that a problem of different datetime strings formatting between
    asp.net and ms sql has been covered here widely, but what I couldn't
    find is the 100% safe way of getting datetime values from ms sql,
    processing them in asp.net and getting them back into sql without any
    risk with inconsistent Culture settings etc.

    My question is: wouldn't keeping the datetime variables all the time in
    datetime type, without any String conversions, prevent all such
    problems?

    I was trying to check it but there are few obstacles when sticking to
    declarative databinding:

    1) session parameters

    Let's say I'm keeping datetime variable in a session. Then, I want to
    use it as a parameter in a datasource. But the variable in session will
    be boxed to Object type, and I have no control on how datasource will
    cast it - how can I prevent it from casting it to string and inserting
    it into the query as a culture-unsafe string?

    I think Select Parameters collection in Data Source properties might
    help - after choosing session parameter I can show Advanced Properties
    and change it's type (from string to datetime) - will Data Source use
    this information to cast the session variable onto datetime properly?

    2) dropdownlist values

    I want to bind some datetime values to dropdownlist and use its
    selected value as a control parameter of a data source. Does it mean,
    that implicit toString conversion must happen during binding to ddl?
    ddl.selectedValue has String type - does it mean, that everything bound
    to ddl is converted to string - no way to prevent it? If it's true,
    then how would it be done in case of datetime, which may be casted to
    string in many different ways (because of formatting possibilities)?
    Would standard datetime.toString() be used when populating ddl?


    thanks a lot for any insight
    cheers
    HP
    H5N1, Oct 9, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    686
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Replies:
    7
    Views:
    1,543
  3. rbt
    Replies:
    3
    Views:
    339
    Fredrik Lundh
    Feb 14, 2005
  4. Aussie Rules

    safest way to pass parameters between pages

    Aussie Rules, Oct 9, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    553
    Steven Cheng[MSFT]
    Oct 9, 2007
  5. J. Shane Kunkle

    Safest way to pass data between web apps?

    J. Shane Kunkle, Mar 11, 2005, in forum: ASP .Net Security
    Replies:
    4
    Views:
    439
    Paul Glavich [MVP ASP.NET]
    Mar 14, 2005
Loading...

Share This Page