vba 使用 getstring 在 ADO 中选择特定列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/298326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:04:25  来源:igfitidea点击:

Selecting particular columns in ADO using getstring

vbams-accessaccess-vbagetstring

提问by tksy

When we use getstring to get data from a recordset (ADO) then it returns all the columns.

当我们使用 getstring 从记录集 (ADO) 获取数据时,它会返回所有列。

If only certain columns are required, how do we modify the getstring statement?

如果只需要某些列,我们如何修改 getstring 语句?

回答by Fionnuala

You can take a step back and build the recordset with only the fields (columns) that you want, for example:

您可以退后一步,仅使用所需的字段(列)构建记录集,例如:

strSQL="SELECT ID, FName, SName FROM Members"
rs.Open strSQL, cn

a=rs.GetString

回答by Tor Haugen

You can't. GetString returns all columns of all or a specified number of rows. You'll need to loop through the recordset, getting the columns you want explicitly.

你不能。GetString 返回所有行或指定行数的所有列。您需要遍历记录集,明确获取所需的列。

It's all in the documentation.

这一切都在文档中

回答by Philippe Grondier

You can also use a combination of join and getrows

您还可以结合使用 join 和 getrows

myString = join(rs.getrows( , , myColumn),";")
  • rsGetrows returns an array containing only the myColumn's values
  • Join will transfer the array in a string like "value1;value2; ..."
  • rsGetrows 返回一个只包含 myColumn 值的数组
  • Join 将在字符串中传输数组,如“value1;value2; ...”

Check the exact syntax as this was written on the fly

检查确切的语法,因为这是即时编写的

EDIT: unfortunately, it cannot be that straight as .getrows will return a 2 dimensions array. Are there any functions that can extract a one dimension array from a 2 dimensions one? It can be written easily, can't it?

编辑:不幸的是,它不能那么直,因为 .getrows 将返回一个二维数组。是否有任何函数可以从二维数组中提取一维数组?它可以很容易地写出来,不是吗?