ado记录集中字段的序号位置 [英] ordinal position of fields in ado recordsets

查看:66
本文介绍了ado记录集中字段的序号位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用ado记录集中的值填充数组

(多行)


我在记录集中使用光标的绝对位置定义

要填充的数组行。我有一个解决方法,因为缺少

a方式来定义一个字段的序数位置(增加一个

计数器变量),但感觉很原始:


dim Fld as Field

dim rst1 as new adodb.recordset

dim varArray()

dim intfieldmarker is integer


Redim varArray(rst1.recordcount,rst1.Fields.count)


rst1.MoveFirst


Do While Not rst1.EOF

intfieldMarker = 0

每个Fld在rst1.Fields

varArray(rst1.AbsolutePosition,intfieldMarker) = Fld

intfieldMarker = intfieldMarker + 1

下一个Fld

rst1.MoveNext

循环


如果我使用DAO,我可以调用每个字段的序号位置,并且

使用它来指示我的数组的列。但似乎这种方法并不是ADO可用的b $ b。有没有人知道一些东西比增加一个柜台有点风险?


是否有可能,例如将字段名称存储在第一行

数组,然后以某种方式使用这些字段名作为指向数组的

列的指针?只是一个想法...

解决方案

绝对最简单的方法是使用GetRows方法


Dim varArray作为变体


varArray = rst1.GetRows


然后你有一个二维数组,其第一个维度是

列第二个维度是行。 (与你定义你的数组的方式相反的方式相反)


或者(按现在的方式按行获取行)


dim Fld as Field

dim rst1 as new adodb.recordset

dim varArray()

dim intfieldmarker as integer

dim lngRowCount as

with rst1

.MoveLast

Redim varArray(0到.RecordCount -1,0到.Fields.count -1)


.MoveFirst

lngRowCount = -1

Do Until .EOF

lngRowCount = lngRowCount + 1

对于intfieldmarker = 0 To .Fields.Count -1

varArray(lngRowCount,intfieldMarker)=。fields( intfieldMarker)

下一个Fld

rst1.MoveNext

循环

结束


-


Terry Kreft

" Donald Grove" <做********* @ verizon.net>在消息中写道

news:74 ******************************** @ 4ax.com ...

我想用ado记录集中的值填充数组
(多行)0

我使用光标的绝对位置记录集来定义要填充的数组的行。我有一个解决方法,因为缺少一种方法来定义一个字段的序数位置(增加一个
计数器变量),但它感觉很原始:

dim Fld as Field
dim rst1 as new adodb.recordset
dim varArray()
dim intfieldmarker是整数

Redim varArray(rst1.recordcount,rst1.Fields.count)

rst1.MoveFirst

不要rst1.EOF
intfieldMarker = 0
对于每个Fld在rst1.Fields
varArray(rst1.AbsolutePosition) ,intfieldMarker)= Fld
intfieldMarker = intfieldMarker + 1
下一个Fld
rst1.MoveNext
循环

如果我使用DAO,我可以调用序数每个字段的位置,并使用它来指示我的数组的列。但似乎这种方法不适用于ADO。有没有人知道比增加一个计数器有点风险?

是否有可能,例如将字段名称存储在数组的第一行
然后以某种方式使用这些字段名作为数组的
列的指针?只是一个想法......



" Donald Grove" <做********* @ verizon.net>在消息中写道

news:74 ******************************** @ 4ax.com ...

我想用ado记录集中的值填充数组
(多行)

我在记录集中使用光标的绝对位置定义要填充的数组的行。我有一个解决方法,因为缺少一种方法来定义一个字段的序数位置(增加一个
计数器变量),但它感觉很原始:

dim Fld as Field
dim rst1 as new adodb.recordset
dim varArray()
dim intfieldmarker是整数

Redim varArray(rst1.recordcount,rst1.Fields.count)

rst1.MoveFirst

不要rst1.EOF
intfieldMarker = 0
对于每个Fld在rst1.Fields
varArray(rst1.AbsolutePosition) ,intfieldMarker)= Fld
intfieldMarker = intfieldMarker + 1
下一个Fld
rst1.MoveNext
循环

如果我使用DAO,我可以调用序数每个字段的位置,并使用它来指示我的数组的列。但似乎这种方法不适用于ADO。有没有人知道比增加一个计数器有点风险?

是否有可能,例如将字段名称存储在数组的第一行
然后以某种方式使用这些字段名作为数组的
列的指针?只是一个想法......



为什么不在一行中呢?

varArray = rst1.GetRows


如果你真的不得不做其他事情,你为什么不简单地使用两个

计数器lngRow和lngCol这样做而不参考

AbsolutePosition属性,即1-基于你的数组似乎是基于零的



我也不明白你可以用DAO记录集做什么你可以''用ADO支付
。假设其名称为FirstField,这两个都将获得

记录集中第一个字段的值。

rst.Fields(0).Value

rst.Fields(" FirstField")。值


嗯,再想一想我会得到Rows / Columns这个版本
方式


dim rst1 as new adodb.recordset

dim varTemp as Variant

dim varArray()

dim intfieldmarker为整数

dim lngRowCount as


varTemp = rst1.GetRows


设置rst1 =没有


''然后交换数组

redim varArray(lbound(vartemp,2)到ubound(vartemp,2), lbound(vartemp,

1)到ubound(vartemp,1))


对于intfieldmarker = lbound(vartemp,1)到ubound(vartemp,1)

对于lngRowCount = lbound(vartemp,2)到ubound(vartemp,2)

varArray(lngRowCount,intfieldmarker)=

varTemp(in tfieldmarker,lngRowCount)

下一页

下一页

-


Terry Kreft

" Terry Kreft" < TE ********* @ mps.co.uk>在消息中写道

news:od ******************** @ karoo.co.uk ...

绝对最简单的方法是使用GetRows方法

Dim varArray作为变体

varArray = rst1.GetRows

然后你有一个二维数组的第一个维度是
列,第二个维度是行。 (与你定义阵列的方式相反)。

或者(按现在的方式逐行获取行)

dim Fld as field
dim rst1 as new adodb.recordset
dim varArray()
dim intfieldmarker as integer
dim lngRowCount as

with rst1
.MoveLast
Redim varArray(0到.RecordCount -1,0到.Fields.count -1)

.MoveFirst
lngRowCount = -1
Do Until .EOF
lngRowCount = lngRowCount + 1
对于intfieldmarker = 0 To .Fields.Count -1
varArray(lngRowCount,intfieldMarker)=
..fields(intfieldMarker)Next Fld
rst1.MoveNext
循环结束

-

特里克雷夫特

唐纳德格罗夫 <做********* @ verizon.net>在消息中写道
新闻:74 ******************************** @ 4ax.com ... < blockquote class =post_quotes>我想用ado记录集中的值填充数组
(多行)0

我使用记录集中光标的绝对位置来定义
要填充的数组的行。我有一个解决方法,因为缺少一种方法来定义一个字段的序数位置(增加一个
计数器变量),但它感觉很原始:

dim Fld as Field
dim rst1 as new adodb.recordset
dim varArray()
dim intfieldmarker是整数

Redim varArray(rst1.recordcount,rst1.Fields.count)

rst1.MoveFirst

不要rst1.EOF
intfieldMarker = 0
对于每个Fld在rst1.Fields
varArray(rst1.AbsolutePosition) ,intfieldMarker)= Fld
intfieldMarker = intfieldMarker + 1
下一个Fld
rst1.MoveNext
循环

如果我使用DAO,我可以调用序数每个字段的位置,并使用它来指示我的数组的列。但似乎这种方法不适用于ADO。有没有人知道比增加一个计数器有点风险?

是否有可能,例如将字段名称存储在数组的第一行
然后以某种方式使用这些字段名作为数组的
列的指针?只是一个想法......




I want to populate an array with values from an ado recordset
(multiple rows)

I use the absolute position of the cursor in the recordset to define
the row of my array to be populated. I have a workaround for lack of
a way to define the ordinal position of a field (incrementing a
counter variable), but it feels so primitive:

dim Fld as Field
dim rst1 as new adodb.recordset
dim varArray()
dim intfieldmarker is integer

Redim varArray(rst1.recordcount, rst1.Fields.count)

rst1.MoveFirst

Do While Not rst1.EOF
intfieldMarker = 0
For Each Fld In rst1.Fields
varArray(rst1.AbsolutePosition, intfieldMarker) = Fld
intfieldMarker = intfieldMarker + 1
Next Fld
rst1.MoveNext
Loop

If I used DAO, I could call the ordinal position of each field, and
use that to indicate the column of my array. But that method isn''t
available with ADO, it seems. Does anyone know something a little
less risky than incrementing a counter?

Is it possible, for instance to store the field names in the first row
of the array, and then somehow use those fieldnames as pointers to the
column of the array? Just a thought...

解决方案

The absolute simplest way is to use the GetRows method

Dim varArray as variant

varArray = rst1.GetRows

You then have a two dimensional array the first dimension of which is the
columns the second dimenstion is the rows. (the opposite way round to how
you''ve defined your array).

Alternatively (to get rows by columns as you have now)

dim Fld as Field
dim rst1 as new adodb.recordset
dim varArray()
dim intfieldmarker as integer
dim lngRowCount as long
with rst1
.MoveLast
Redim varArray(0 to .RecordCount -1, 0 to .Fields.count -1)

.MoveFirst
lngRowCount = -1
Do Until .EOF
lngRowCount = lngRowCount + 1
For intfieldmarker = 0 To .Fields.Count -1
varArray(lngRowCount, intfieldMarker) = .fields(intfieldMarker)
Next Fld
rst1.MoveNext
Loop
End With

--

Terry Kreft
"Donald Grove" <do*********@verizon.net> wrote in message
news:74********************************@4ax.com...

I want to populate an array with values from an ado recordset
(multiple rows)0

I use the absolute position of the cursor in the recordset to define
the row of my array to be populated. I have a workaround for lack of
a way to define the ordinal position of a field (incrementing a
counter variable), but it feels so primitive:

dim Fld as Field
dim rst1 as new adodb.recordset
dim varArray()
dim intfieldmarker is integer

Redim varArray(rst1.recordcount, rst1.Fields.count)

rst1.MoveFirst

Do While Not rst1.EOF
intfieldMarker = 0
For Each Fld In rst1.Fields
varArray(rst1.AbsolutePosition, intfieldMarker) = Fld
intfieldMarker = intfieldMarker + 1
Next Fld
rst1.MoveNext
Loop

If I used DAO, I could call the ordinal position of each field, and
use that to indicate the column of my array. But that method isn''t
available with ADO, it seems. Does anyone know something a little
less risky than incrementing a counter?

Is it possible, for instance to store the field names in the first row
of the array, and then somehow use those fieldnames as pointers to the
column of the array? Just a thought...



"Donald Grove" <do*********@verizon.net> wrote in message
news:74********************************@4ax.com...

I want to populate an array with values from an ado recordset
(multiple rows)

I use the absolute position of the cursor in the recordset to define
the row of my array to be populated. I have a workaround for lack of
a way to define the ordinal position of a field (incrementing a
counter variable), but it feels so primitive:

dim Fld as Field
dim rst1 as new adodb.recordset
dim varArray()
dim intfieldmarker is integer

Redim varArray(rst1.recordcount, rst1.Fields.count)

rst1.MoveFirst

Do While Not rst1.EOF
intfieldMarker = 0
For Each Fld In rst1.Fields
varArray(rst1.AbsolutePosition, intfieldMarker) = Fld
intfieldMarker = intfieldMarker + 1
Next Fld
rst1.MoveNext
Loop

If I used DAO, I could call the ordinal position of each field, and
use that to indicate the column of my array. But that method isn''t
available with ADO, it seems. Does anyone know something a little
less risky than incrementing a counter?

Is it possible, for instance to store the field names in the first row
of the array, and then somehow use those fieldnames as pointers to the
column of the array? Just a thought...


Why not do it in one line?
varArray=rst1.GetRows

If you really had to do something else, why would you not simply use two
counters lngRow and lngCol to do this without referring to the
AbsolutePosition property which is 1-based whereas your array seems to be
zero-based.

I also don''t understand what you can do with DAO recordsets that you can''t
with ADO. Both of these will get you the value of the first field in the
recordset assuming its name is "FirstField".
rst.Fields(0).Value
rst.Fields("FirstField").Value


Hmmm, Thinking about this again I would get the Rows/Columns version this
way

dim rst1 as new adodb.recordset
dim varTemp as Variant
dim varArray()
dim intfieldmarker as integer
dim lngRowCount as long

varTemp = rst1.GetRows

Set rst1 = nothing

'' Then swap the array around
redim varArray(lbound(vartemp, 2) to ubound(vartemp, 2), lbound(vartemp,
1) to ubound(vartemp, 1))

For intfieldmarker = lbound(vartemp, 1) to ubound(vartemp, 1)
For lngRowCount = lbound(vartemp, 2) to ubound(vartemp, 2)
varArray(lngRowCount , intfieldmarker ) =
varTemp(intfieldmarker, lngRowCount)
Next
Next
--

Terry Kreft
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:od********************@karoo.co.uk...

The absolute simplest way is to use the GetRows method

Dim varArray as variant

varArray = rst1.GetRows

You then have a two dimensional array the first dimension of which is the
columns the second dimenstion is the rows. (the opposite way round to how
you''ve defined your array).

Alternatively (to get rows by columns as you have now)

dim Fld as Field
dim rst1 as new adodb.recordset
dim varArray()
dim intfieldmarker as integer
dim lngRowCount as long
with rst1
.MoveLast
Redim varArray(0 to .RecordCount -1, 0 to .Fields.count -1)

.MoveFirst
lngRowCount = -1
Do Until .EOF
lngRowCount = lngRowCount + 1
For intfieldmarker = 0 To .Fields.Count -1
varArray(lngRowCount, intfieldMarker) = ..fields(intfieldMarker) Next Fld
rst1.MoveNext
Loop
End With

--

Terry Kreft
"Donald Grove" <do*********@verizon.net> wrote in message
news:74********************************@4ax.com...

I want to populate an array with values from an ado recordset
(multiple rows)0

I use the absolute position of the cursor in the recordset to define
the row of my array to be populated. I have a workaround for lack of
a way to define the ordinal position of a field (incrementing a
counter variable), but it feels so primitive:

dim Fld as Field
dim rst1 as new adodb.recordset
dim varArray()
dim intfieldmarker is integer

Redim varArray(rst1.recordcount, rst1.Fields.count)

rst1.MoveFirst

Do While Not rst1.EOF
intfieldMarker = 0
For Each Fld In rst1.Fields
varArray(rst1.AbsolutePosition, intfieldMarker) = Fld
intfieldMarker = intfieldMarker + 1
Next Fld
rst1.MoveNext
Loop

If I used DAO, I could call the ordinal position of each field, and
use that to indicate the column of my array. But that method isn''t
available with ADO, it seems. Does anyone know something a little
less risky than incrementing a counter?

Is it possible, for instance to store the field names in the first row
of the array, and then somehow use those fieldnames as pointers to the
column of the array? Just a thought...




这篇关于ado记录集中字段的序号位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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