發現若將Rst.Open "select * from 某表 where 從某個Form獲取的查詢條件" 改成 Rst.Open "select * from 某表"(相當于不做查詢動作)后, 記錄的瀏覽功能才得以實現. 否則總是出現" EOF或BOF為真 "的錯誤提示.可我明明可以從"某表"中 "select... where..."到好幾個記錄的!
總之如何將"記錄的逐條瀏覽"和"select * from 某表 where 從某個Form獲取的查詢條件" 結合起來?
望予以指點為感!
楊利 2000/4/13
程序代碼:
<%@ LANGUAGE=VBScript %> <!-- #Include file="ADOVBS.INC" --> <html> <head> <title></title> </head> <body BGCOLOR="#FFFFF0"> <h3 align="center"><font face="隸書" color="#004080"><big>現在您可以編輯以下記錄</big></font></h3> <!-- 在服務器上創建 Connection 和 Recordset 對象 --> <% '創建并打開 Connection 對象。 Set cn=Server.CreateObject("ADODB.Connection") cn.Open "DSN=數據庫名" '創建并打開 Recordset 對象。 Set Rst = Server.CreateObject("ADODB.Recordset") Rst.ActiveConnection = cn Rst.CursorType = adOpenKeyset Rst.LockType = adLockOptimistic Rst.Open "select * from 某表 where 性別='"&request.form("t1")&"'"(執行這句大有問題) Rst.Open "select * from 某表 where 性別='男'"(執行這句有點問題) Rst.Open "select * from hr_base"(執行這句沒有問題) ' 檢查 Request.Form 集合以查看所記錄的任何移動。 If Not IsEmpty(Request.Form("MoveAmount")) Then ' 跟蹤該會話的移動數目和方向。 session("Moves") = Session("Moves") + Request.Form("MoveAmount") Clicks = Session("Moves") '移動到上一個已知位置。 Rst.Move CInt(Clicks) '檢查移動為 + 還是 - 并進行錯誤檢查。 If CInt(Request.Form("MoveAmount")) = 1 Then If Rst.EOF Then Session("Moves") = Rst.RecordCount Rst.MoveLast End If Rst.MoveNext End If If Request.Form("MoveAmount") < 1 Then Rst.MovePrevious End If '檢查有無單擊 First Record 或 Last Record 命令按鈕。 If Request.Form("MoveLast") = 3 Then Rst.MoveLast Session("Moves") = Rst.RecordCount End If If Request.Form("MoveFirst") = 2 Then Rst.MoveFirst Session("Moves") = 1 End If End If ' 對 Move Button 單擊組合進行錯誤檢查。 If Rst.EOF Then Session("Moves") = Rst.RecordCount Rst.MoveLast Response.Write "This is the Last Record" End If If Rst.BOF Then Session("Moves") = 1 Rst.MoveFirst Response.Write "This is the First Record" End If %> <!-- 顯示當前記錄數目和記錄集大小--> <h3 align="center"><font face="隸書" color="#004080">共查到</font><font color="#600060"><%=Rst.RecordCount%></font><font face="隸書" color="#004080">條記錄,當前為第</font> <font color="#600060"> <% If IsEmpty(Session("Moves")) Then Session("Moves") =1 End If %> <%Response.Write(Session("Moves") )%> </font><font face="隸書" color="#004080">條記錄</font></h3> <hr align="center"> <p align="center"> <input Type="button" Name="cmdFirst" Value="第一條" style="font-family: 宋體"><input Type="button" Name="cmdDown" Value="上一條"><input Type="button" Name="cmdUp" Value="下一條"><input Type="button" Name="cmdLast" Value="末一條"> </p> <p align="center"><b><font size="5" color="#000080" face="隸書">查詢結果:</font></b></p>
<table> (用于逐條顯示記錄的表格) </table>
<!-- 使用隱含窗體字段將值發送到服務器--> <form Method="Post" Action Name="Form"> <input type="hidden" name="MoveAmount" value="0"><input type="hidden" name="MoveLast" value="0"><input type="hidden" name="MoveFirst" value="0"> </form> </body> <script Language="VBScript"> Sub cmdDown_OnClick '在 Input Boxes 窗體和 Submit 窗體中設置值。 Document.Form.MoveAmount.Value = -1 Document.Form.Submit End Sub Sub cmdUp_OnClick Document.Form.MoveAmount.Value = 1 Document.Form.Submit End Sub Sub cmdFirst_OnClick Document.Form.MoveFirst.Value = 2 Document.Form.Submit End Sub Sub cmdLast_OnClick Document.Form.MoveLast.Value =3 Document.Form.Submit End Sub </script> </html>