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. sql statement ..., how can i resolve this error

sql statement ..., how can i resolve this error

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

    i have made this sql statement and it works well but sometimes it show the result and sometimes not this sql statement between two datepicker it works with some date and the other no and sometime it gives error (out of range date) here is my code cmd.CommandText = "select sum(fatrq1)reglz from reglz where fatrdate between '" + DateTimePicker1.Value + "'and'" + DateTimePicker2.Value + "'" 'fatrq1 dr = cmd.ExecuteReader when i want to put these dates it doesn't works (from 1/1/2007 To 1/7/2007) it may work if i enter another dates what ca i do ??

    W D 2 Replies Last reply
    0
    • M magedhv

      i have made this sql statement and it works well but sometimes it show the result and sometimes not this sql statement between two datepicker it works with some date and the other no and sometime it gives error (out of range date) here is my code cmd.CommandText = "select sum(fatrq1)reglz from reglz where fatrdate between '" + DateTimePicker1.Value + "'and'" + DateTimePicker2.Value + "'" 'fatrq1 dr = cmd.ExecuteReader when i want to put these dates it doesn't works (from 1/1/2007 To 1/7/2007) it may work if i enter another dates what ca i do ??

      W Offline
      W Offline
      WhiteGirl23
      wrote on last edited by
      #2

      maybe the sql server doesn't accept this format for date. see http://sqljunkies.com/Article/6676BEAE-1967-402D-9578-9A1C7FD826E5.scuk I hope this help

      M 1 Reply Last reply
      0
      • M magedhv

        i have made this sql statement and it works well but sometimes it show the result and sometimes not this sql statement between two datepicker it works with some date and the other no and sometime it gives error (out of range date) here is my code cmd.CommandText = "select sum(fatrq1)reglz from reglz where fatrdate between '" + DateTimePicker1.Value + "'and'" + DateTimePicker2.Value + "'" 'fatrq1 dr = cmd.ExecuteReader when i want to put these dates it doesn't works (from 1/1/2007 To 1/7/2007) it may work if i enter another dates what ca i do ??

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

        Use a parameterize query string to do this and you won't have to worry about what format the dates and times show up in in your string. The method that you used resulted in a string like this:

        ....WHERE fatrdate BETWEEN '#7/25/2007 12:24:31 PM#'and'...
        

        which SQL Server doesn't like. Read Colin Angus Mackay's article on SQL Injection Attacks[^] and you'll find out why what you're doing doesn't work and how dangerous it is.

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

        1 Reply Last reply
        0
        • W WhiteGirl23

          maybe the sql server doesn't accept this format for date. see http://sqljunkies.com/Article/6676BEAE-1967-402D-9578-9A1C7FD826E5.scuk I hope this help

          M Offline
          M Offline
          magedhv
          wrote on last edited by
          #4

          after editing my code like that Dim x, y As String x = DateTimePicker1.Value y = DateTimePicker2.Value cmd.CommandText = "select sum(fatrq1)reglz, convert(varchar,fatrdate,101) from reglz where fatrdate between '" + x + "'and'" + y + "'" dr = cmd.ExecuteReader the vb gives me error Column 'reglz.fatrdate' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.

          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