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. Select statement

Select statement

Scheduled Pinned Locked Moved Visual Basic
questiondatabasehelp
4 Posts 4 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.
  • M Offline
    M Offline
    minniemooo
    wrote on last edited by
    #1

    What is wrong with my statement? Dim mySelectQuery As String = "SELECT * FROM table where Rdate between '" & FromDate.Value & "'" And "'" & ToDate.Value & "'" Rdate is a value from the database. I get this error : Cast from string "SELECT * FROM table where recv" to type 'Long' is not valid. Thank you

    S S C 3 Replies Last reply
    0
    • M minniemooo

      What is wrong with my statement? Dim mySelectQuery As String = "SELECT * FROM table where Rdate between '" & FromDate.Value & "'" And "'" & ToDate.Value & "'" Rdate is a value from the database. I get this error : Cast from string "SELECT * FROM table where recv" to type 'Long' is not valid. Thank you

      S Offline
      S Offline
      Stephan Pilz
      wrote on last edited by
      #2

      All 3 expressions for between must be the same datatype. If Rdate is from Type Date you must convert FromData.value and ToDate.value to a Date. This conversion depends on the database system. Look there for more information. If you use SQLServer see in Transact-SQL-Help for command 'CAST', 'CONVERT','BETWEEN' and 'DATETIME'. Regards Stephan

                     \\\\\\|///
                   \\\\  - -  //
                    (  @ @  )
      

      +---------------oOOo-(_)-oOOo-----------------+
      | Stephan Pilz stephan.pilz@stephan-pilz.de |
      | www.stephan-pilz.de |
      | ICQ#: 127823481 |
      +-----------------------Oooo------------------+
      oooO ( )
      ( ) ) /
      \ ( (_/
      \_)

      1 Reply Last reply
      0
      • M minniemooo

        What is wrong with my statement? Dim mySelectQuery As String = "SELECT * FROM table where Rdate between '" & FromDate.Value & "'" And "'" & ToDate.Value & "'" Rdate is a value from the database. I get this error : Cast from string "SELECT * FROM table where recv" to type 'Long' is not valid. Thank you

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

        Rigard wrote:

        String = "SELECT * FROM table where Rdate between '" & FromDate.Value & "'" And "'" & ToDate.Value & "'"

        Try this (Assuming RDate is of DateTime type): "SELECT * FROM table where Rdate between #" & FromDate.Value & "#" And "#" & ToDate.Value & "#"


        I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

        1 Reply Last reply
        0
        • M minniemooo

          What is wrong with my statement? Dim mySelectQuery As String = "SELECT * FROM table where Rdate between '" & FromDate.Value & "'" And "'" & ToDate.Value & "'" Rdate is a value from the database. I get this error : Cast from string "SELECT * FROM table where recv" to type 'Long' is not valid. Thank you

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

          Rigard wrote:

          What is wrong with my statement?

          You inject values into the SQL, which is a security risk and causes other problems. Use parameterised queries instead of injecting values.


          Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

          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