2013-12-17 42 views
0

我正在使用以下代碼來過濾日期範圍內的某些結果。它只是給我帶來了一些錯誤的結果......就像我使用的過濾器是錯誤的。日期範圍查詢不能正常工作

這是代碼:

<html> 
<head> 
<title>Classic ASP Search Access Database Demo</title> 
<style> 
body {font-family:arial;} 
table.search {width:200px;} 
table.recordset {width:600px;padding:0px;} 
div.recordset {width:618px;height:300px;overflow-y:scroll;border:1px solid black;} 
th.recordset {color:white;background:black;padding:2px;} 
.search {width:100px;} 
.column-1 {width:200px;text-align:left;} 
.column-2 {width:200px;text-align:left;} 
.column-3 {width:200px;text-align:left;} 
.eof {color:red;padding:4px;} 
td.recordset {border-bottom: 1px solid silver;} 
</style> 
</head> 
<body> 

<% 


sSearch1 = Request.Form("search1") 
sSearch2 = Request.Form("search2") 


%> 

<form action="1emvolio.asp" method="post"> 
<table class="search"> 
<tr>from 
<td class="search"><input name="search1" type="date" value="<%=sSearch1%>"></td> 

</tr> 

    <tr>to 
<td class="search"><input name="search2" type="date" value="<%=sSearch2%>"></td> 
<td class="search"><input type="submit" value="Search"> 
</tr> 
</table> 
</form> 

<h3>Search Results</h3> 

<div class="recordset"> 
<table class="recordset" cellspacing="0"> 
<tr> 
<th class="column-1 recordset">Description 1</th> 
<th class="column-2 recordset">Description 2</th> 
<th class="column-3 recordset">Description 3</th> 
</tr> 

<% 


If sSearch1 <> "" Then 




sSearch1 = Trim(Replace(sSearch1,"'","''")) 



Set oConnection = Server.CreateObject("ADODB.Connection") 

oConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb") 


Set oRecordset = oConnection.Execute("SELECT * " & _ 
            "FROM emvolio " & _ 
            "WHERE next_date between '" & sSearch1 & "' and '" & sSearch2 "'") 



If not oRecordset.EOF Then 
Do While not oRecordset.EOF 
%> 

<tr> 
<td class="column-1 recordset"><%=oRecordset("chip")%></td> 
<td class="column-2 recordset"><%=oRecordset("emvolio")%></td> 
<td class="column-3 recordset"><%=oRecordset("next_date")%></td> 
</tr> 

<% 
oRecordset.MoveNext 
Loop 
Else 
%> 

<tr> 
<td class="eof" colspan="3">No Records</td> 
</tr> 

<% 

end if 
end if 
response.write(sSearch2) 
response.write(sSearch1) 

%> 

</table> 
</div> 
</body> 
</html> 

我相信問題是場「NEXT_DATE」不是日期字段,以便它只是讀取DD/MM/YYYY的每一個第一個數字。我使用的訪問數據庫中的 我必須使用「next_date」字段的文本類型才能使該.asp頁面正常工作。當我使用日期類型時,出現錯誤。

請幫助

回答