以下范例说明了访问分级 recordset 中的行的所需步骤:
authors 和 titleauthors 表中的 recordset 对象通过 author id 进行关联。
外循环显示每个作者的姓名、州/省别和身份。
每行所追加的 recordset 都从 fields 集合进行检索并分配给 rsttitleauthor。
内循环显示追加的 recordset 中每行的四个字段。
(stayinsync 属性是为了说明而设置为 false 的,以便您可以在每次外循环中显性地看见子集更改。但是,如果在步骤 3 中的赋值被移动到步骤 2 第一行之前,范例将会更有效,所以赋值只执行一次。然后将 stayinsync 属性设为 true,这样无论 rst 何时移动到新行,rsttitleauthor 都将隐性和自动地更改为相应的子集。)
范例
sub datashape()
dim cnn as new adodb.connection
dim rst as new adodb.recordset
dim rsttitleauthor as new adodb.recordset
cnn.provider = "msdatashape"
cnn.open "data provider=msdasql;" & _
"dsn=vfox;uid=sa;pwd=vfox;database=pubs”
‘步骤 1
rst.stayinsync = false
rst.open "shape {select * from authors}
append ({select * from titleauthor}
relate au_id to au_id) as chaptitleauthor",
cnn
‘步骤 2
while not rst.eof
debug.print rst("au_fname"), rst("au_lname"),
rst("state"), rst("au_id")
‘步骤 3
set rsttitleauthor = rst("chaptitleauthor").value
‘步骤 4
while not rsttitleauthor.eof
debug.print rsttitleauthor(0), rsttitleauthor(1),
rsttitleauthor(2), rsttitleauthor(3)
rsttitleauthor.movenext
wend
rst.movenext
wend
end sub
形状语法格式
以下是创建 shape 命令的规范语法。
必需的语法项为尖括号 (“<>”) 界定的文本字符串。
可选项由方括号 (“[ ]”) 界定。
任选其一项用竖线 (“|”) 隔开。
重复的可选项用省略号 (“…”) 表示。
alpha 表示字母字符串。
digit 表示数字字符串。
unicode-digit 表示由 unicode 数字组成的字符串。
所有其他项目均为文字。
项目 定义
<shape-command>
shape [<table-exp> ][[as] <alias>]][<shape-action>]
<table-exp>
{<native-sql-statement>} |(<shape-command>) |
table <quoted-name> |
<quoted-name>
<shape-action>
append <aliased-field-list> | compute <aliased-field-list>
[by <field-list> ][[as] <alias>]]
<aliased-field-list>
<aliased-field> [, <aliased-field…]
<aliased-field>
<field-exp> [[as] <alias>]
<field-exp>
(<relation-exp>) |<calculated-exp>
<relation_exp>
<table-exp> [[as] <alias>] relate <relation-cond-list>
<relation-cond-list>
<relation-cond> [, <relation-cond>…]
<relation-cond>
<field-name> to <child-ref>
<child-ref>
<field-name> | parameter <param-ref>
<param-ref>
<number>
<field-list>
<field-name [, <field-name>]
<calculated-exp>
sum(<qualified-field-name>) |avg(<qualified-field-name>) |
min(<qualified-field-name>) |
max(<qualified-field-name>) |
count(<alias> | <qualified-field-name>) |
stdev(<qualified-field-name>) |
any(<qualified-field-name>) |
calc(<expresion>)
<qualified-field-name>
<alias>.[<alias>…]<field-name>
<alias>
<quoted-name>
<field-name>
<quoted-name>
<quoted-name>
"<string>" | <string> |
[<string>] |
<name>
<name>
alpha [ alpha | digit | _ | # …]
<number>
digit [digit…]
<string>
unicode-char [unicode-char…]
<expression>
visual basic for applications 表达式,其操作数是相同行中其他非 calc 列。
