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. General Programming
  3. Visual Basic
  4. Problem with between function with date timepicker

Problem with between function with date timepicker

Scheduled Pinned Locked Moved Visual Basic
databasehelpsql-serversysadmin
3 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.
  • N Offline
    N Offline
    nazimghori
    wrote on last edited by
    #1

    hello i am using SQL server 2005 as my back end now i want report of like from this date to this date...for that i wrote query like format of my date is dd/MMM/yyyy

    If optn1.Checked = True Or optn3.Checked = True Then
    sqlstr="select * from des_mast"
    sqlstr = sqlstr & "where pickup_date between '" & Me.dtp1.Value & "' and '" & Me.dtp2.Value & "'"
    End If

    but while executing this query shows an error message like "incorrect syntax near the keyword 'between'" please suggest i cant get where the problem is thank you

    T D 2 Replies Last reply
    0
    • N nazimghori

      hello i am using SQL server 2005 as my back end now i want report of like from this date to this date...for that i wrote query like format of my date is dd/MMM/yyyy

      If optn1.Checked = True Or optn3.Checked = True Then
      sqlstr="select * from des_mast"
      sqlstr = sqlstr & "where pickup_date between '" & Me.dtp1.Value & "' and '" & Me.dtp2.Value & "'"
      End If

      but while executing this query shows an error message like "incorrect syntax near the keyword 'between'" please suggest i cant get where the problem is thank you

      T Offline
      T Offline
      tonym001
      wrote on last edited by
      #2

      Try formatting the date to mm/dd/yyyy. If that really is your code your sqlstr looks like this "Select from des_mastwhere pickup_date..."

      TonyMac

      1 Reply Last reply
      0
      • N nazimghori

        hello i am using SQL server 2005 as my back end now i want report of like from this date to this date...for that i wrote query like format of my date is dd/MMM/yyyy

        If optn1.Checked = True Or optn3.Checked = True Then
        sqlstr="select * from des_mast"
        sqlstr = sqlstr & "where pickup_date between '" & Me.dtp1.Value & "' and '" & Me.dtp2.Value & "'"
        End If

        but while executing this query shows an error message like "incorrect syntax near the keyword 'between'" please suggest i cant get where the problem is thank you

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Change this SQL statement to a parameterized query, then you won't have to worry about the format of the date values coming from the controls. It'll be handled for you and will also prevent some injection attacks in your code.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        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