MySQL rs.Fields(0) 是什么意思?(ADODB) VBA

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2829804/
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-08-31 16:02:41  来源:igfitidea点击:

what does rs.Fields(0) mean? (ADODB) VBA

sqlmysqlexcelvba

提问by l--''''''---------''''''''''''

dim rs As ADODB.Recordset
...
...
...
capture_id = rs.Fields(0)

what does .Fields(0) mean?

.Fields(0) 是什么意思?

回答by SQLMenace

the first column from the recordset (0) is the first (1) is the second etc etc

记录集 (0) 中的第一列是第一列 (1) 是第二列等等

example, if this is your query

例如,如果这是您的查询

select LastName, FirstName 
from YourTable

In this case s.Fields(0)would return column LastNameand rs.Fields(1)would return column FirstName

在这种情况下s.Fields(0)将返回列LastNamers.Fields(1)将返回列FirstName

回答by Matt

It's pulling the first column from the current row in the result set.

它从结果集中的当前行中拉出第一列。

Fields(x)lets you access fields by a numerical index starting at 0.

Fields(x)允许您通过从 0 开始的数字索引访问字段。

Edit:

编辑

Example:

例子:

If the result set has two columns: fooand bar..

如果结果集有两列:foobar..

rs.Fields(0)would return the valueof column foo,

rs.Fields(0)将返回column的foo

and

rs.Fields(1)would return the valueof column bar.

rs.Fields(1)将返回column的bar

回答by Tony Toews

I would NEVER, EVER use this syntax. This is dependant on the query alwayshaving the same field in the first position.

我永远不会使用这种语法。这取决于查询始终在第一个位置具有相同的字段。

Furthermore this would only save a minute amount of time. (As in milliseconds if not less.)

此外,这只会节省一分钟的时间。(如果不是更少的话,以毫秒为单位。)

Please, for the love of God, per proper programming practice, change that to use the field name. This almost, but not quite, belongs on the www.dailywtf.com website.

为了上帝的爱,请按照正确的编程实践将其更改为使用字段名称。这几乎但不完全属于 www.dailywtf.com 网站。