Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: Select on 'Time' portion of DateTime fields


Message #1 by "John A Conte" <jconte8@y...> on Wed, 19 Mar 2003 18:15:04
Hello Folks,

I have loaded an ADO table with a set of records containing reservation 
information.  The fields are (Access db):
resvID (autonum) key
resvDate (datetime)
resvStartTime (datetime)
resvEndTime (datetime)
...

I am now looping through an array of time slots looking for reservations 
(on a particular day - already filtered) for that particular slot.  I am 
trying a Select directly against the ADO table, like 

(c#)
string sql = "resvTimeStart < #" + rowTime.AddMinutes(30).TimeOfDay 
+           "# AND resvTimeEnd > #" + rowTime.TimeOfDay + "#";
DataRow [] drr = dtResvdb.Select( sql );


but select turns out empty (but I know there is data in the dtResvdb).
sql = "resvTimeStart < #09:30:00# AND resvTimeEnd > #09:00:00#" during a 
particular loop searching for reservations between 9-9:30 AM.

I have recently learned (from kind reply of this list), that I needed to 
use #date# for datetime sql.  Is there something special that must be done 
to select against the 'time' portion of datetime?

Thanks in advance - John
Message #2 by "John A Conte" <jconte8@y...> on Wed, 19 Mar 2003 21:33:23
I'll answer my own question this time after creating a small tool to check 
my sql.  resvTimeStart<#13:00:00# does indeed work.  But the overall logic 
does not.  

I suppose my problem is the usage of the datatable.select method .
I have 

sql = "resvTimeStart < #" + rowTime.AddMinutes(30).TimeOfDay  + 
      "# AND resvTimeEnd > #" + rowTime.TimeOfDay + "#";
drr = dtResvdb.Select( sql );
//check to see if any returned
if (drr.Length  == 0 ) { ...

although the sql statement works against the db table directly (i've 
tested this) , it does not return any rows within the .select method.  

Does anyone have any idea why????

Any help is appreciated!  John

  Return to Index