Home All Groups Group Topic Archive Search About
Author
6 Jan 2006 5:32 AM
steve
Hi All

I am using Access 2003 and VS 2005 Professional

I retrieve data from an access DB into a datatable then need to select rows
that match a short time value

I can retrieve by time from Access OK
e.g sql = "Select [Details], [mytime], [endtime], [mydate], [member] from
[appointments] where [instructornumber] = " & instructornumber & " and
[mydate] = #" &           Format(mydate, "MMM d, yyyy") & "# and [mytime] =
#" & Format(dr("Time"), "t") & "# order by mydate"
dtweek = getdata(sql)

but I can't get the datatable.select to return rows with the same matching
criteria
e.g
drrows = dtweek.Select("mydate = #" & Format(mydate, "MMM d, yyyy") & "#
AND mytime = #" & Format(dr("Time"), "t") & "#")

In the sql line 'mydate' is an access 2003 DateTime field with a format of
Medium Time
In the select line dr("Time") is a datacolumn from a datatable of type
System.DateTime

The following works OK... drrows = dtweek.Select("mydate = #" &
Format(mydate, "MMM d, yyyy") & "#")
It is the time field that is the problem

Any ideas please

Regards
Steve

Author
6 Jan 2006 7:23 AM
Kevin Yu [MSFT]
Hi steve,

The datatable engine is not so powerful as the Jet is.  It cannot parse all
the formats of DateTime that Jet does. When filtering a date from
DataTable, I suggest you try to use #mm/dd/yyyy# like "Birthdate <
#1/31/82#".

Also, it is not safe to concatenate strings to build the SQL statement.
Hackers can use injection attack with this. You can use the Parameters to
get over this.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."