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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. DateTime syntax help

DateTime syntax help

Scheduled Pinned Locked Moved Database
helpcsharpdatabasequestion
4 Posts 3 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.
  • B Offline
    B Offline
    Branislav Vidovic
    wrote on last edited by
    #1

    Hello guys.. Looks like I just need a litle help on my SQL syntax in C#.NET I have a field in my database which is DateTime type. Looks like I can't get the syntax right for comparing the value from the textBox with the field in database. Now what I have looks like: DateTime ShDate = DateTime.Parse(txtDate.Text); cmd1.CommandText = "SELECT ShipedDate FROM Details WHERE Details.ShipedDate = #ShDate#"; When I fill dataset with the adapter which has this SelectCommand it will report error in date in the syntax expresion. Now the variable ShDate has a DateTime type in C# and it stores a date from the textbox with a help of conversion and it is in a correct format(I cheked while debuging). I think the problem is somewhere here = #ShDate#. I bet I am missing some quotation marks ("") or single quote(''). So does any one have a clue? Thanks..

    S E 3 Replies Last reply
    0
    • B Branislav Vidovic

      Hello guys.. Looks like I just need a litle help on my SQL syntax in C#.NET I have a field in my database which is DateTime type. Looks like I can't get the syntax right for comparing the value from the textBox with the field in database. Now what I have looks like: DateTime ShDate = DateTime.Parse(txtDate.Text); cmd1.CommandText = "SELECT ShipedDate FROM Details WHERE Details.ShipedDate = #ShDate#"; When I fill dataset with the adapter which has this SelectCommand it will report error in date in the syntax expresion. Now the variable ShDate has a DateTime type in C# and it stores a date from the textbox with a help of conversion and it is in a correct format(I cheked while debuging). I think the problem is somewhere here = #ShDate#. I bet I am missing some quotation marks ("") or single quote(''). So does any one have a clue? Thanks..

      S Offline
      S Offline
      Senu Gandhi
      wrote on last edited by
      #2

      Hi, I think you are just now migrating from MS-Acccess. When comparing date in SQL Server no need of "#". Just simply " = ShDate " is enough. Senthil

      1 Reply Last reply
      0
      • B Branislav Vidovic

        Hello guys.. Looks like I just need a litle help on my SQL syntax in C#.NET I have a field in my database which is DateTime type. Looks like I can't get the syntax right for comparing the value from the textBox with the field in database. Now what I have looks like: DateTime ShDate = DateTime.Parse(txtDate.Text); cmd1.CommandText = "SELECT ShipedDate FROM Details WHERE Details.ShipedDate = #ShDate#"; When I fill dataset with the adapter which has this SelectCommand it will report error in date in the syntax expresion. Now the variable ShDate has a DateTime type in C# and it stores a date from the textbox with a help of conversion and it is in a correct format(I cheked while debuging). I think the problem is somewhere here = #ShDate#. I bet I am missing some quotation marks ("") or single quote(''). So does any one have a clue? Thanks..

        E Offline
        E Offline
        edukulla
        wrote on last edited by
        #3

        Can you try this out... DateTime ShDate = DateTime.Parse(txtDate.Text); cmd1.CommandText = 'SELECT ShipedDate FROM Details WHERE Details.ShipedDate =%' + ShDate + '%'; See if it helps. Thanks! Santhosh

        Santhosh Kumar Edukulla

        1 Reply Last reply
        0
        • B Branislav Vidovic

          Hello guys.. Looks like I just need a litle help on my SQL syntax in C#.NET I have a field in my database which is DateTime type. Looks like I can't get the syntax right for comparing the value from the textBox with the field in database. Now what I have looks like: DateTime ShDate = DateTime.Parse(txtDate.Text); cmd1.CommandText = "SELECT ShipedDate FROM Details WHERE Details.ShipedDate = #ShDate#"; When I fill dataset with the adapter which has this SelectCommand it will report error in date in the syntax expresion. Now the variable ShDate has a DateTime type in C# and it stores a date from the textbox with a help of conversion and it is in a correct format(I cheked while debuging). I think the problem is somewhere here = #ShDate#. I bet I am missing some quotation marks ("") or single quote(''). So does any one have a clue? Thanks..

          E Offline
          E Offline
          edukulla
          wrote on last edited by
          #4

          Apologies, ignore my previous post.. Try this DateTime ShDate = DateTime.Parse(txtDate.Text); cmd1.CommandText = 'SELECT ShipedDate FROM Details WHERE Details.ShipedDate like' + '''' + '%' + ShDate + '%' + ''''; I tried it on my sql box and it worked. Hope this helps Thanks!

          Santhosh Kumar Edukulla

          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