GetRows的 [英] GetRows

查看:95
本文介绍了GetRows的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我在使用Access 2000从桌子上直接读到一个

数组时遇到了麻烦。


Dim db As Database

Dim rsTime作为记录集

Dim TimeArray As Variant


设置db = CurrentDb

设置rsTime = db.OpenRecordset(" Time Record")

''只有在存在记录时才加载数组

If(rsTime.RecordCount 0)然后

rsTime.MoveLast:rsTime.MoveFirst

''记录数= 10

TimeArray = rsTime.GetRows

结束如果

只显示加载第一条记录。我只看到第0行

vResult = TimeArray(0,0)产生良好的数据

vResult = TimeArray(0,1)给我一个下标超出范围 ;

错误


任何想法都会受到赞赏。

Hank Reed

解决方案



Hank写道:


你好,

我在使用Access 2000直接从表中读取

数组时遇到了麻烦。


Dim db作为数据库

Dim rsTime作为记录集

Dim TimeArray作为变体


设置db = CurrentDb

设置rsTime = db.OpenRecordset(" Time记录")

''只有在存在记录时才加载数组

If(rsTime.RecordCount 0)然后

rsTime.MoveLast:rsTime.MoveFirst

''记录数= 10

TimeArray = rsTime.GetRows

结束如果

只显示加载第一条记录。我只看到第0行

vResult = TimeArray(0,0)产生良好的数据

vResult = TimeArray(0,1)给我一个下标超出范围 ;

错误


任何想法都将不胜感激。



我认为您需要指定从记录集

返回的行数。请尝试以下方法:


Dim db作为数据库

Dim rsTime作为记录集

Dim TimeArray As Variant


设置db = CurrentDb

设置rsTime = db.OpenRecordset(" Time Record")

''仅在存在记录时加载数组

If(rsTime.RecordCount 0)然后

rsTime.MoveLast

''记录数= 10

TimeArray = rsTime .GetRows(rsTime.RecordCount)

结束如果


HTH,

布鲁斯


布鲁斯,


完美!这么简单。

显然另一种方式是遍历表格,一次只能获得一个记录。


谢谢你你的时间,

Hank


" Hank" < ha ******** @ aol.comwrote in

新闻:11 ********************** @ m79g2000cwm.googlegr psps.com:


我在使用Access 2000从表中直接读入

数组时遇到问题。



为什么你会这样做呢?记录集是一个数组。为什么不

只需使用记录集做你想做的事情?


-

David W. Fenton http://www.dfenton.com/

usenet at dfenton dot com http://www.dfenton.com/DFA/


Hello,
I''m having trouble reading from a table directly into an
array using Access 2000.

Dim db As Database
Dim rsTime As Recordset
Dim TimeArray As Variant

Set db = CurrentDb
Set rsTime = db.OpenRecordset("Time Record")
'' Only load array if records exist
If (rsTime.RecordCount 0) Then
rsTime.MoveLast: rsTime.MoveFirst
'' The record count = 10
TimeArray = rsTime.GetRows
End If
It only appears to load the first record. I see only row 0
vResult = TimeArray(0,0) results in good data
vResult = TimeArray(0,1) gives me a "Subscript out of Range"
error

Any ideas would be appreciated.
Hank Reed

解决方案


Hank wrote:

Hello,
I''m having trouble reading from a table directly into an
array using Access 2000.

Dim db As Database
Dim rsTime As Recordset
Dim TimeArray As Variant

Set db = CurrentDb
Set rsTime = db.OpenRecordset("Time Record")
'' Only load array if records exist
If (rsTime.RecordCount 0) Then
rsTime.MoveLast: rsTime.MoveFirst
'' The record count = 10
TimeArray = rsTime.GetRows
End If
It only appears to load the first record. I see only row 0
vResult = TimeArray(0,0) results in good data
vResult = TimeArray(0,1) gives me a "Subscript out of Range"
error

Any ideas would be appreciated.

I think you need to specify the number of rows you want returned from
your recordset. Try the following:

Dim db As Database
Dim rsTime As Recordset
Dim TimeArray As Variant

Set db = CurrentDb
Set rsTime = db.OpenRecordset("Time Record")
'' Only load array if records exist
If (rsTime.RecordCount 0) Then
rsTime.MoveLast
'' The record count = 10
TimeArray = rsTime.GetRows(rsTime.RecordCount)
End If

HTH,
Bruce


Bruce,

Perfect! So simple.
Apparently the other way would be to traverse the table getting
one record at a time.

Thanks for your time,
Hank


"Hank" <ha********@aol.comwrote in
news:11**********************@m79g2000cwm.googlegr oups.com:

I''m having trouble reading from a table directly into an
array using Access 2000.

Why would you bother doing that? A recordset is an array. Why not
just use the recordset to do what you want?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/


这篇关于GetRows的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆