Filter 和 RecordCount 属性示例 (VB)Filter and RecordCount properties example (VB)

09/18/2015

本文内容

适用于:Access 2013、Office 2013Applies to: Access 2013, Office 2013

本示例打开 Pubs 数据库 Publishers(发行商)表上的一个 Recordset。This example open a Recordset on the Publishers table in the Pubs database. 然后使用 Filter 属性将可见的记录数限制为发行商属于特定国家/地区的记录。It then uses the Filter property to limit the number of visible records to those publishers in a particular country/region. RecordCount 属性用于显示筛选和未筛选的记录集之间的差值。The RecordCount property is used to show the difference between the filtered and unfiltered recordsets.

'BeginFilterVB

'To integrate this code

'replace the data source and initial catalog values

'in the connection string

Public Sub Main()

On Error GoTo ErrorHandler

' recordset variables

Dim rstPublishers As ADODB.Recordset

Dim Cnxn As ADODB.Connection

Dim strCnxn As String

Dim SQLPublishers As String

' criteria variables

Dim intPublisherCount As Integer

Dim strCountry As String

Dim strMessage As String

' open connection

Set Cnxn = New ADODB.Connection

strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _

"Initial Catalog='Pubs';Integrated Security='SSPI';"

Cnxn.Open strCnxn

' open recordset with data from Publishers table

Set rstPublishers = New ADODB.Recordset

SQLPublishers = "publishers"

rstPublishers.Open SQLPublishers, strCnxn, adOpenStatic, , adCmdTable

intPublisherCount = rstPublishers.RecordCount

' get user input

strCountry = Trim(InputBox("Enter a country to filter on (e.g. USA):"))

If strCountry <> "" Then

' open a filtered Recordset object

rstPublishers.Filter = "Country ='" & strCountry & "'"

If rstPublishers.RecordCount = 0 Then

MsgBox "No publishers from that country."

Else

' print number of records for the original recordset

' and the filtered recordset

strMessage = "Orders in original recordset: " & _

vbCr & intPublisherCount & vbCr & _

"Orders in filtered recordset (Country = '" & _

strCountry & "'): " & vbCr & _

rstPublishers.RecordCount

MsgBox strMessage

End If

End If

' clean up

rstPublishers.Close

Cnxn.Close

Set rstPublishers = Nothing

Set Cnxn = Nothing

Exit Sub

ErrorHandler:

' clean up

If Not rstPublishers Is Nothing Then

If rstPublishers.State = adStateOpen Then rstPublishers.Close

End If

Set rstPublishers = Nothing

If Not Cnxn Is Nothing Then

If Cnxn.State = adStateOpen Then Cnxn.Close

End If

Set Cnxn = Nothing

If Err <> 0 Then

MsgBox Err.Source & "-->" & Err.Description, , "Error"

End If

End Sub

'EndFilterVB

备注

[!注释] 如果知道要选择的数据,通过这种方式打开 Recordset 通过比使用 SQL 语句效率更高。本示例演示如何仅创建一个 Recordset 并获取特定国家/地区的记录。When you know the data you want to select, it's usually more efficient to open a Recordset with an SQL statement. This example shows how you can create just one Recordset and obtain records from a particular country/region.

'BeginFilter2VB

'To integrate this code

'replace the data source and initial catalog values

'in the connection string

Public Sub Main()

On Error GoTo ErrorHandler

Dim rstPublishers As ADODB.Recordset

Dim Cnxn As ADODB.Connection

Dim strSQLPublishers As String

Dim strCnxn As String

' open connection

Set Cnxn = New ADODB.Connection

strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _

"Initial Catalog='Pubs';Integrated Security='SSPI';"

Cnxn.Open strCnxn

' open recordset with criteria from Publishers table

Set rstPublishers = New ADODB.Recordset

strSQLPublishers = "SELECT * FROM publishers WHERE Country = 'USA'"

rstPublishers.Open strSQLPublishers, Cnxn, adOpenStatic, adLockReadOnly, adCmdText

' print recordset

rstPublishers.MoveFirst

Do While Not rstPublishers.EOF

Debug.Print rstPublishers!pub_name & ", " & rstPublishers!country

rstPublishers.MoveNext

Loop

' clean up

rstPublishers.Close

Cnxn.Close

Set rstPublishers = Nothing

Set Cnxn = Nothing

Exit Sub

ErrorHandler:

' clean up

If Not rstPublishers Is Nothing Then

If rstPublishers.State = adStateOpen Then rstPublishers.Close

End If

Set rstPublishers = Nothing

If Not Cnxn Is Nothing Then

If Cnxn.State = adStateOpen Then Cnxn.Close

End If

Set Cnxn = Nothing

If Err <> 0 Then

MsgBox Err.Source & "-->" & Err.Description, , "Error"

End If

End Sub

'EndFilter2VB

mysql recordcount_Filter 和 RecordCount 属性示例 (VB)相关推荐

  1. php pdo 与对比mysql,php使用mysqli和pdo扩展,测试对比连接mysql数据库的效率完整示例...

    php使用mysqli和pdo扩展,测试对比连接mysql数据库的效率完整示例 本文实例讲述了php使用mysqli和pdo扩展,测试对比连接mysql数据库的效率.分享给大家供大家参考,具体如下: ...

  2. MySQL基础 - 列的属性

    简单的查询和插入的语句 简单的查询语句 如果我们想查看某个表里已经存储了哪些数据,可以用下边这个语句: SELECT * FROM 表名; 比如我们想看看前边创建的first_table表中有哪些数据 ...

  3. python和mysql数据类型对应,MySQL和Python交互的示例

    一.准备数据 创建数据表 -- 创建 "京东" 数据库 create database jing_dong charset=utf8; -- 使用 "京东" 数 ...

  4. .net连接mysql数据_.net连接MYSQL数据库的方法及示例!

    连接MYSQL数据库的方法及示例 方法一: 使用MYSQL推出的MySQL Connector/Net is an ADO.NET driver for MySQL 该组件为MYSQL为ADO.NET ...

  5. mysql修改主键属性_mysql如何改变主键属性

    mysql改变主键属性的方法:1.使用关键字modify,代码为[alter table tbl_name modify.....]:2.使用关键字change,代码为[alter table tbl ...

  6. php过滤数据库就报错,php过滤掉emoji等无法存入MySQL数据库的字符简单示例

    这篇文章主要为大家详细介绍了php过滤掉emoji等无法存入MySQL数据库的字符简单示例,具有一定的参考价值,可以用来参考一下. 对php过滤掉emoji等无法存入MySQL数据库的字符简单示例感兴 ...

  7. aspx mysql类_aspx中的mysql操作类sqldatasource使用示例分享

    复制代码 代码如下: /p> "http://www.w3.org/TR/xhtmlll/DTD/xhtmlll.dtd"> asp.net to mysql asp. ...

  8. MySQL中修改列属性时造成comment属性丢失

    修改字段定义的时候,要把整个字段的全部的定义都写上,举个栗子: 原字段定义: state  varchar(50) NOT NULL DEFAULT '' COMMENT '产品资料状态' 需求:修改 ...

  9. jsf tree组件_JSF UI组件标签属性示例教程

    jsf tree组件 JSF provides a wide variety of ui component tags along with a long range of attributes. T ...

  10. MySQL数据类型及字段属性

    MySQL 数据类型MySQL中定义数据字段的类型对你数据库的优化是非常重要的.MySQL支持多种类型,大致可以分为三类: 数值 日期/时间 字符串(字符) 数值类型 MySQL支持所有标准SQL数值 ...

最新文章

  1. 【Qt】QtCreator无法调试终端程序,启动报错SIGSTOP
  2. 【zt】我所经历的ERP项目的失败
  3. 博士申请 | 澳大利亚悉尼科技大学招收人工智能/软件工程方向全奖博士生
  4. eslint 无法格式化ts_vscode保存代码,自动按照eslint规范格式化代码设置
  5. mysql循环map_java Map 遍历速度最优解
  6. 中国内裤衬里行业市场供需与战略研究报告
  7. 谈谈基类与子类的this指针(C++)
  8. Python字符串splitlines()
  9. Mysql 存储类型范围
  10. uniapp路线规划
  11. 让一台电脑死机至少需要几行代码
  12. Linux性能分析工具perf基础使用介绍
  13. 解决pycharm导入自己写的模块飘红问题
  14. 社群公会GangSDK:程序员入行AI领域需要哪些技能?
  15. Python lambda 介绍
  16. 算法题 牌型判断 Java
  17. 视频点播技术android,基于Android机顶盒VOD视频点播系统的设计与实现
  18. 流程图GoJS用于HTML图表的JavaScript库
  19. 基于FPGA的1553B通信模块的设计(转)
  20. vue粒子特效插件——vue-particles

热门文章

  1. 下手重了,我把同事小刘的腿打断了...
  2. 绘制地图其实并不难!如何绘制地图?看看Smartbi的制作方法
  3. Spring @ResponseBody未生效,无法返回json数据 前端页面显示404
  4. 旅行商问题和背包问题
  5. python画风羽及风羽定义
  6. php阴阳万年历转换的接口,万年历接口
  7. 华硕双屏笔记本windows系统驱动安装
  8. html外链视频,WordPress文章内容中插入外链视频的通用iframe方法
  9. 人工智能冬去春来 从技术导向向应用导向转变的自然结果
  10. arcgis导出的图片无效_img影像在arcgis中生成JPG图片空白求解