本文介绍了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。有没有人知道一些东西比增加一个柜台有点风险? 是否有可能,例如将字段名称存储在第一行 数组,然后以某种方式使用这些字段名作为指向数组的 列的指针?只是一个想法... 解决方案 为什么不在一行中呢? varArray = rst1.GetRows 如果你真的不得不做其他事情,你为什么不简单地使用两个 计数器lngRow和lngCol这样做而不参考 AbsolutePosition属性,即1-基于你的数组似乎是基于零的。 我也不明白你可以用DAO记录集做什么你可以''用ADO支付。假设其名称为FirstField,这两个都将获得 记录集中第一个字段的值。 rst.Fields(0).Value rst.Fields(" FirstField")。值 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 definethe row of my array to be populated. I have a workaround for lack ofa way to define the ordinal position of a field (incrementing acounter variable), but it feels so primitive:dim Fld as Fielddim rst1 as new adodb.recordsetdim varArray()dim intfieldmarker is integerRedim varArray(rst1.recordcount, rst1.Fields.count)rst1.MoveFirstDo While Not rst1.EOFintfieldMarker = 0For Each Fld In rst1.FieldsvarArray(rst1.AbsolutePosition, intfieldMarker) = FldintfieldMarker = intfieldMarker + 1Next Fldrst1.MoveNextLoopIf I used DAO, I could call the ordinal position of each field, anduse that to indicate the column of my array. But that method isn''tavailable with ADO, it seems. Does anyone know something a littleless risky than incrementing a counter?Is it possible, for instance to store the field names in the first rowof the array, and then somehow use those fieldnames as pointers to thecolumn of the array? Just a thought... 解决方案Why not do it in one line?varArray=rst1.GetRowsIf you really had to do something else, why would you not simply use twocounters lngRow and lngCol to do this without referring to theAbsolutePosition property which is 1-based whereas your array seems to bezero-based.I also don''t understand what you can do with DAO recordsets that you can''twith ADO. Both of these will get you the value of the first field in therecordset assuming its name is "FirstField".rst.Fields(0).Valuerst.Fields("FirstField").Value 这篇关于ado记录集中字段的序号位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-08 00:18