Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Datetime - Independent Format

SQL Datetime - Independent Format

Scheduled Pinned Locked Moved Database
helpcsharpdatabasesql-serversysadmin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Seraphin
    wrote on last edited by
    #1

    A big problem is a Datetime object in the CommandText property. I always get an error. Is .NET unable to convert Datetime object into the right SQL Server system format? When it's possible ... how to solve it?

    C 1 Reply Last reply
    0
    • S Seraphin

      A big problem is a Datetime object in the CommandText property. I always get an error. Is .NET unable to convert Datetime object into the right SQL Server system format? When it's possible ... how to solve it?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Seraphin wrote: A big problem is a Datetime object in the CommandText property. Why are you putting a DateTime in the CommandText property? Seraphin wrote: Is .NET unable to convert Datetime object into the right SQL Server system format? .NET is perfectly capbable of converting a DateTime object to what ever format you wish in multiple calendars (should you so wish it). Seraphin wrote: how to solve it? If you need to use a DataTime (or anything else for that matter) in a query you should use parameters. This reduces the possibility of security holes.

      SqlCommand cmd = new SqlCommand();
      cmd.CommandText = "SELECT * FROM MyTable WHERE SomeDate > @theDate";
      cmd.Parameters.Add("@theDate", myDateTimeObject);

      Does this help?


      My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      S 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Seraphin wrote: A big problem is a Datetime object in the CommandText property. Why are you putting a DateTime in the CommandText property? Seraphin wrote: Is .NET unable to convert Datetime object into the right SQL Server system format? .NET is perfectly capbable of converting a DateTime object to what ever format you wish in multiple calendars (should you so wish it). Seraphin wrote: how to solve it? If you need to use a DataTime (or anything else for that matter) in a query you should use parameters. This reduces the possibility of security holes.

        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "SELECT * FROM MyTable WHERE SomeDate > @theDate";
        cmd.Parameters.Add("@theDate", myDateTimeObject);

        Does this help?


        My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

        S Offline
        S Offline
        Seraphin
        wrote on last edited by
        #3

        Thank you. That's what I want.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups