是否可以使用 JavaScript 和 cscript 枚举 ADO Recordset 的字段名称?

发布于 2024-08-23 18:40:16 字数 752 浏览 7 评论 0原文

我正在编写一些在旧的 Windows NT 机器上运行的脚本。我计划使用基于命令的脚本主机(cscript)来执行它们。该脚本正在查询一些 SQL 数据,我想从记录集中检索字段名称,但它似乎不起作用。

这是我正在使用的代码:

rs.open(query, conn, adOpenForwardOnly, adLockReadOnly);


rs.MoveFirst();
while(!rs.eof) {
 for(field in rs.Fields) {
  WScript.Echo(field.Name); /* outputs nothing */

 }
    WScript.Echo(rs.Fields("column")); /* outputs the column value for this record (as expected)*/

 rs.MoveNext();
}

rs.close();

编辑:

也尝试过:

while(!rs.eof) {
    WScript.Echo(rs.Fields.length); /* doesn't print anything */
    for(var i = 0; i< rs.Fields.length; i++) { /* loop isn't entered */
        WScript.Echo(rs.Fields(i).Name);
    }
    rs.MoveNext();
}

I am writing some scripts to run on old Windows NT machines. I am planning on using the command-based script host (cscript) to execute them. The script are querying some SQL data and I want to retrieve the field names from the RecordSet, but it doesn't seem to work.

This is the code I'm using:

rs.open(query, conn, adOpenForwardOnly, adLockReadOnly);


rs.MoveFirst();
while(!rs.eof) {
 for(field in rs.Fields) {
  WScript.Echo(field.Name); /* outputs nothing */

 }
    WScript.Echo(rs.Fields("column")); /* outputs the column value for this record (as expected)*/

 rs.MoveNext();
}

rs.close();

Edit:

Tried this as well:

while(!rs.eof) {
    WScript.Echo(rs.Fields.length); /* doesn't print anything */
    for(var i = 0; i< rs.Fields.length; i++) { /* loop isn't entered */
        WScript.Echo(rs.Fields(i).Name);
    }
    rs.MoveNext();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉默的熊 2024-08-30 18:40:16

试试这个:

  WScript.Echo(rs.Fields(0).Name);

..然后通过索引进行交互。

Try this:

  WScript.Echo(rs.Fields(0).Name);

..then interate through the index.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文