|
-
July 30th, 2010, 11:29 AM
#1
[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
-
July 30th, 2010, 12:36 PM
#2
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.
-
July 30th, 2010, 12:52 PM
#3
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.
-
July 30th, 2010, 01:40 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|