编程论坛
400万+工程师在用
华为|鸿蒙开发者日
直播报名
400万+工程师在用
华为|鸿蒙开发者日
直播报名

电子发烧友网工程师

17年用户 16436经验值
擅长:可编程逻辑 MEMS/传感技术 测量仪表 模拟技术 控制/MCU RF/无线
私信 关注

Find 方法范例 (VB)

2009-1-8 10:20

<p><font face="Verdana">Find 方法范例 (VB)</font></p><font face="Verdana">
<p><br/>本范例使用 Recordset 对象的 Find 方法来定位 Pubs 数据库中的业务标题,并对其进行计数。本范例假设基本提供者不支持相似的功能。</p>
<p><br/>Public Sub Main()<br/>&nbsp;&nbsp;&nbsp; FindX<br/>End Sub</p>
<p>Public Sub FindX()<br/>Dim cnn As New ADODB.Connection<br/>Dim rst As New ADODB.Recordset<br/>Dim mark As Variant<br/>Dim count As Integer</p>
<p>count = 0<br/>cnn.Open "DSN=Pubs; Provider=MSDASQL; uid=sa; pwd=;"<br/>rst.Open "SELECT title_id FROM titles", cnn, _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; adOpenStatic, adLockReadOnly, adCmdText</p>
<p>' The default parameters are sufficient to search forward<br/>' through a Recordset.</p>
<p>rst.Find "title_id LIKE 'BU%'"</p>
<p>' Skip the current record to avoid finding the same row repeatedly.<br/>' The bookmark is redundant because Find searches from the current<br/>' position.</p>
<p>Do While rst.EOF &lt;&gt; True&nbsp;&nbsp;&nbsp; 'Continue IF last find succeeded.<br/>&nbsp;&nbsp;&nbsp; debug.Print "Title ID: "; rst!title_id<br/>&nbsp;&nbsp;&nbsp; count = count + 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Count the last title found.<br/>&nbsp;&nbsp;&nbsp; mark = rst.Bookmark&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Note current position.<br/>&nbsp;&nbsp;&nbsp; rst.Find "title_id LIKE 'BU%'", 1, adSearchForward, mark<br/>Loop</p>
<p>rst.Close<br/>cnn.Close<br/>Debug.Print "The number of business titles is " &amp; count</p>
<p>End Sub</p>
<p></font>&nbsp;</p>

更多回帖

打开APP