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 query for filtering Access database by date

sql query for filtering Access database by date

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

    Hi, I am trying to fill the gridview with the data from an Access table for a range of dates.

        Dim cmd1 As String = "Select \* from " & inpTable & " Where mdateTime = '29/09/2011'" 
        MsgBox("cmd= " & cmd1)
        Dim da As OleDbDataAdapter
        Try
            da = New OleDbDataAdapter(cmd1, myConnection)
        Catch ex As Exception    ' Catch the error.
            MsgBox(ex.ToString)   ' Show friendly error message.
        End Try
    
        Try
            Dim table As New DataTable
            da.Fill(table)
            DataGridView1.DataSource = table
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        myConnection.Close()
    

    Command as it appears in the MsgBox Select * from rawClimateData Where mdateTime > 30/09/2011 10:45:00 AM The query works if I am not filtering the data base; however, with filter I get the syntax error "missing operator". Any suggestion??

    J D C 3 Replies Last reply
    0
    • A Amanjot

      Hi, I am trying to fill the gridview with the data from an Access table for a range of dates.

          Dim cmd1 As String = "Select \* from " & inpTable & " Where mdateTime = '29/09/2011'" 
          MsgBox("cmd= " & cmd1)
          Dim da As OleDbDataAdapter
          Try
              da = New OleDbDataAdapter(cmd1, myConnection)
          Catch ex As Exception    ' Catch the error.
              MsgBox(ex.ToString)   ' Show friendly error message.
          End Try
      
          Try
              Dim table As New DataTable
              da.Fill(table)
              DataGridView1.DataSource = table
          Catch ex As Exception
              MsgBox(ex.ToString)
          End Try
          myConnection.Close()
      

      Command as it appears in the MsgBox Select * from rawClimateData Where mdateTime > 30/09/2011 10:45:00 AM The query works if I am not filtering the data base; however, with filter I get the syntax error "missing operator". Any suggestion??

      J Offline
      J Offline
      JR212
      wrote on last edited by
      #2

      dates are in "sqldateformat" #mm-dd-yyyy# Jan

      1 Reply Last reply
      0
      • A Amanjot

        Hi, I am trying to fill the gridview with the data from an Access table for a range of dates.

            Dim cmd1 As String = "Select \* from " & inpTable & " Where mdateTime = '29/09/2011'" 
            MsgBox("cmd= " & cmd1)
            Dim da As OleDbDataAdapter
            Try
                da = New OleDbDataAdapter(cmd1, myConnection)
            Catch ex As Exception    ' Catch the error.
                MsgBox(ex.ToString)   ' Show friendly error message.
            End Try
        
            Try
                Dim table As New DataTable
                da.Fill(table)
                DataGridView1.DataSource = table
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            myConnection.Close()
        

        Command as it appears in the MsgBox Select * from rawClimateData Where mdateTime > 30/09/2011 10:45:00 AM The query works if I am not filtering the data base; however, with filter I get the syntax error "missing operator". Any suggestion??

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

        Rewrite this as a parameterized query and you won't have to worry about what "format" the datetime objects are in. Just Google for ".NET Sql parameterized query" and you'll find tons of exampels.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        1 Reply Last reply
        0
        • A Amanjot

          Hi, I am trying to fill the gridview with the data from an Access table for a range of dates.

              Dim cmd1 As String = "Select \* from " & inpTable & " Where mdateTime = '29/09/2011'" 
              MsgBox("cmd= " & cmd1)
              Dim da As OleDbDataAdapter
              Try
                  da = New OleDbDataAdapter(cmd1, myConnection)
              Catch ex As Exception    ' Catch the error.
                  MsgBox(ex.ToString)   ' Show friendly error message.
              End Try
          
              Try
                  Dim table As New DataTable
                  da.Fill(table)
                  DataGridView1.DataSource = table
              Catch ex As Exception
                  MsgBox(ex.ToString)
              End Try
              myConnection.Close()
          

          Command as it appears in the MsgBox Select * from rawClimateData Where mdateTime > 30/09/2011 10:45:00 AM The query works if I am not filtering the data base; however, with filter I get the syntax error "missing operator". Any suggestion??

          C Offline
          C Offline
          coded007
          wrote on last edited by
          #4

          use this will work

          Dim cmd1 As String = "Select * from " & inpTable & " Where convert(datetime,mdateTime,101) = convert(datetime,'09/29/2011',101)"

          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