[RESOLVED] Time Range not working for me.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Time Range not working for me.

  1. #1
    Join Date
    Dec 2009
    Posts
    596

    [RESOLVED] Time Range not working for me.

    Hi everyone. It's me again. I'm stuck on selecting a time range. I get a Data type mismatch error message with my current SQL statement. In the Access 2007 table my EventTime column is defined as date time with medium time format. I also tried changing it to long time format. Using Visual Basic 2008. Anyone know how to make this work?

    Code:
        Private Function GetNumerator(ByVal TableArg As String) As Integer
            Dim connection As OleDb.OleDbConnection = NewConnection()
            Dim command As OleDb.OleDbCommand = connection.CreateCommand
            Dim OurAdapter As New OleDb.OleDbDataAdapter
            Dim OurDataset As New DataSet
            Dim OurDataTable As New DataTable
    
            Try
                command = connection.CreateCommand
                command.CommandText = "SELECT EventID,Location,Species,EventDate,EventTime,FilePath FROM " & TableArg & _
               " Where (EventTime >= '" & #6:00:00 AM# & "'" & " AND EventTime <= " & "'" & #1:00:00 PM# & "')" & ""
                OurAdapter.SelectCommand = command
                OurAdapter.Fill(OurDataset, TableArg)
                OurDataTable = OurDataset.Tables(TableArg)
            Catch ex As Exception
                MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
            End Try
            Return OurDataTable.Rows.Count
        End Function

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,786

    Re: Time Range not working for me.

    Your string is not formatted correctly should be more like the following.

    Code:
    (EventTime >= #6:00:00 AM#  AND EventTime <=  #1:00:00 PM#)
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Dec 2009
    Posts
    596

    Re: Time Range not working for me.

    Thanks DataMiser that worked perfectly right off the bat. Although I could have sworn I tried it like that but obviously i didn't. Thanks again man.

  4. #4
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,786

    Re: [RESOLVED] Time Range not working for me.

    No Problem
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center