简体   繁体   English

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

[英]Selecting particular columns in ADO using getstring

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语句?

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

You can't. 你不能 GetString returns all columns of all or a specified number of rows. GetString返回所有行或指定行数的所有列。 You'll need to loop through the recordset, getting the columns you want explicitly. 您将需要遍历记录集,以显式获取所需的列。

It's all in the documentation . 全部在文档中

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 rsGetrows返回仅包含myColumn值的数组
  • Join will transfer the array in a string like "value1;value2; ..." 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. 编辑:不幸的是,它不能像.getrows那样直接返回2维数组。 Are there any functions that can extract a one dimension array from a 2 dimensions one? 是否有任何函数可以从2维一维数组中提取一维数组? It can be written easily, can't it? 它很容易写,不是吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM