⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdmthmovex.htm

📁 ADO使用手册,非常详细
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML dir=ltr>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=gb2312"><title>Move 方法范例</title>
<style>@import url(msdn_ie4.css);</style>
</HEAD>
<BODY>
<h3><a name="mdmthmovex"></a>Move 方法范例</h3>
<p>
该范例使用 Move 方法定位基于用户输入的记录指针。</p>
<pre>Public Sub MoveX()   Dim rstAuthors As ADODB.Recordset
   Dim strCnn As String
   Dim varBookmark As Variant
   Dim strCommand As String
   Dim lngMove As Long   ' 打开 Authors 表的记录集。
      strCnn = "Provider=sqloledb;" &amp; _
      "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
   Set rstAuthors = New ADODB.Recordset
   rstAuthors.CursorType = adOpenStatic
   ' 使用客户端游标以允许使用 AbsolutePosition 属性。
   rstAuthors.CursorLocation = adUseClient
   rstAuthors.Open "SELECT au_id, au_fname, au_lname, city, state " &amp; _
      "FROM Authors ORDER BY au_lname", strCnn, , , adCmdText
         rstAuthors.MoveFirst   Do While True
      ' 显示有关当前记录的信息并询问要移动的记录数。      strCommand = InputBox( _
         "Record " &amp; rstAuthors.AbsolutePosition &amp; _
         " of " &amp; rstAuthors.RecordCount &amp; vbCr &amp; _
         "Author: " &amp; rstAuthors!au_fname &amp; _
         " " &amp; rstAuthors!au_lname &amp; vbCr &amp; _
         "Location: " &amp; rstAuthors!City &amp; _
         ", " &amp; rstAuthors!State &amp; vbCr &amp; vbCr &amp; _
         "Enter number of records to Move " &amp; _
         "(positive or negative).")      If strCommand = "" Then Exit Do      ' 保存书签以防 Move 向前或向后移动太远。
      varBookmark = rstAuthors.Bookmark      ' Move 方法需要数据类型为长整型的参数。
      lngMove = CLng(strCommand)
      rstAuthors.<i>Move</i> lngMove      ' 捕获 BOF 或 EOF。
      If rstAuthors.BOF Then
         MsgBox "Too far backward! " &amp; _
            "Returning to current record."
         rstAuthors.Bookmark = varBookmark
      End If
      If rstAuthors.EOF Then
         MsgBox "Too far forward! " &amp; _
            "Returning to current record."
         rstAuthors.Bookmark = varBookmark
      End If
   Loop
   rstAuthors.CloseEnd Sub
</pre>
<p class=label>
<b>VBScript 版本</b></p>
<p>
下面是使用 VBScript 编写、并用于 Active Server Page (ASP) 的相同范例。如需查看该完整功能范例,请使用与 IIS 一同安装并位于 C:\InetPub\ASPSamp\AdvWorks 的数据源 AdvWorks.mdb,来创建名为 AdvWorks 的系统“数据源名称”(DSN)。这是 Microsoft Access 数据库文件。请使用查找命令定位文件 Adovbs.inc,并将其放入计划使用的目录中。请将以下代码剪切并粘贴到记事本或其他文本编辑器中,另存为“Move.asp”。这样,便可在任何客户端浏览器中查看结果。</p>
<p>
请输入字母或非整数查看错误处理的运作。</p>
<pre>&lt;!-- #Include file="ADOVBS.INC" --&gt;
&lt;% Language = VBScript %&gt;
&lt;HTML&gt;&lt;HEAD&gt;
&lt;TITLE&gt;ADO Move Methods&lt;/TITLE&gt;&lt;/HEAD&gt;
&lt;BODY&gt; 
&lt;FONT FACE="MS SANS SERIF" SIZE=2&gt;
&lt;Center&gt;
&lt;H3&gt;ADO Move Methods&lt;/H3&gt;&lt;%
 ' 创建并打开 Connection 对象。
Set OBJdbConnection = Server.CreateObject("ADODB.Connection") 
OBJdbConnection.Open "AdvWorks" 
' 创建并打开 Recordset 对象。
Set RsCustomerList = Server.CreateObject("ADODB.Recordset")
RsCustomerList.ActiveConnection = OBJdbConnection
RsCustomerList.CursorType = adOpenKeyset
RsCustomerList.LockType = adLockOptimistic
RsCustomerList.Source = "Customers"RsCustomerList.Open ' 检查该会话中用户移动的数目,以窗体中的数量作为增量。
Session("Clicks") = Session("Clicks") + Request.Form("MoveAmount")
Clicks = Session("Clicks")
' 移动到上次已知的记录集位置加上由 Form Post 方法传递的数量。
RsCustomerList.Move CInt(Clicks)' 出错处理。
   If RsCustomerList.EOF Then
         Session("Clicks") = RsCustomerList.RecordCount
         Response.Write "This is the Last Record"
         RsCustomerList.MoveLast
      Else If RsCustomerList.BOF Then
         Session("Clicks") = 1
         RsCustomerList.MoveFirst
         Response.Write "This is the First Record"
      End If
   End If%&gt;&lt;H3&gt;Current Record Number is &lt;BR&gt;
&lt;% If Session("Clicks") = 0 Then 
Session("Clicks") = 1
End If
Response.Write(Session("Clicks") )%&gt; of &lt;%=RsCustomerList.RecordCount%&gt;&lt;/H3&gt;
&lt;HR&gt;
&lt;Center&gt;&lt;TABLE COLSPAN=8 CELLPADDING=5 BORDER=0&gt;&lt;!-- Customer 表的 BEGIN 列标头行 --&gt;&lt;TR&gt;&lt;TD ALIGN=CENTER BGCOLOR="#008080"&gt;
&lt;FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1&gt;Company Name&lt;/FONT&gt;
&lt;/TD&gt;
&lt;TD ALIGN=CENTER BGCOLOR="#008080"&gt;
&lt;FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1&gt;Contact Name&lt;/FONT&gt;
&lt;/TD&gt;
&lt;TD ALIGN=CENTER WIDTH=150 BGCOLOR="#008080"&gt;
&lt;FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1&gt;Phone Number&lt;/FONT&gt;
&lt;/TD&gt;
&lt;TD ALIGN=CENTER BGCOLOR="#008080"&gt;
&lt;FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1&gt;City&lt;/FONT&gt;
&lt;/TD&gt;
&lt;TD ALIGN=CENTER BGCOLOR="#008080"&gt;
&lt;FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1&gt;State/Province&lt;/FONT&gt;
&lt;/TD&gt;&lt;/TR&gt;&lt;!-- 显示 Customer 表的 ADO 数据 --&gt;  &lt;TR&gt;
  &lt;TD BGCOLOR="f7efde" ALIGN=CENTER&gt; 
  &lt;FONT STYLE="ARIAL NARROW" SIZE=1&gt; 
  &lt;%= RSCustomerList("CompanyName")%&gt; 
  &lt;/FONT&gt;&lt;/TD&gt;
  &lt;TD BGCOLOR="f7efde" ALIGN=CENTER&gt;
  &lt;FONT STYLE="ARIAL NARROW" SIZE=1&gt; 
  &lt;%= RScustomerList("ContactLastName") &amp; ", " %&gt; 
  &lt;%= RScustomerList("ContactFirstName") %&gt; 
  &lt;/FONT&gt;&lt;/TD&gt;
  &lt;TD BGCOLOR="f7efde" ALIGN=CENTER&gt;
  &lt;FONT STYLE="ARIAL NARROW" SIZE=1&gt;
 &nbsp; 
  &lt;%= RScustomerList("PhoneNumber")%&gt; 
 &lt;/FONT&gt;&lt;/TD&gt;
  &lt;TD BGCOLOR="f7efde" ALIGN=CENTER&gt;
  &lt;FONT STYLE="ARIAL NARROW" SIZE=1&gt; 
  &lt;%= RScustomerList("City")%&gt; 
  &lt;/FONT&gt;&lt;/TD&gt;
  &lt;TD BGCOLOR="f7efde" ALIGN=CENTER&gt;
  &lt;FONT STYLE="ARIAL NARROW" SIZE=1&gt; 
  &lt;%= RScustomerList("StateOrProvince")%&gt; 
  &lt;/FONT&gt;&lt;/TD&gt;
  &lt;/TR&gt; &lt;/Table&gt;&lt;/FONT&gt;
&lt;HR&gt;
&lt;Input Type = Button Name = cmdDown&nbsp; Value = "&lt;  "&gt;
&lt;Input Type = Button Name = cmdUp Value = " &gt;"&gt;
&lt;H5&gt;Click Direction Arrows for Previous or Next Record
&lt;BR&gt; Click Move Amount to use Move Method
Enter Number of Records to Move + or - &lt;/H5&gt;&lt;Table&gt;&lt;Form Method = Post Action="Move.asp" Name=Form&gt;&lt;TR&gt;&lt;TD&gt;&lt;Input Type="Button" Name = Move Value="Move Amount "&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;
&lt;Input Type="Text" Size="4" Name="MoveAmount" Value = 0&gt;&lt;/TD&gt;&lt;TR&gt;
&lt;/Form&gt;&lt;/Table&gt;&lt;/Center&gt;&lt;/BODY&gt;&lt;Script Language = "VBScript"&gt;Sub Move_OnClick
' 确认输入的移动值为整型。
If IsNumeric(Document.Form.MoveAmount.Value)Then
   Document.Form.MoveAmount.Value = CInt(Document.Form.MoveAmount.Value)
   Document.Form.Submit
Else
   MsgBox "You Must Enter a Number", ,"ADO-ASP Example"
   Document.Form.MoveAmount.Value = 0
End IfEnd SubSub cmdDown_OnClickDocument.Form.MoveAmount.Value = -1
Document.Form.SubmitEnd SubSub cmdUp_OnClickDocument.Form.MoveAmount.Value = 1
Document.Form.SubmitEnd Sub&lt;/Script&gt;
&lt;/HTML&gt;
</pre>
<center> <A HREF="http://www.51windows.Net">www.51windows.Net</A></center>
<SCRIPT LANGUAGE="JavaScript" src="/log/sitelog2.asp"></SCRIPT>
<script src="script.js"></script></BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -