如何使用ADO与JavaScript来获取受语句影响的行数? [英] How can I get the # of rows affected by a statement using ADO with JavaScript?

查看:75
本文介绍了如何使用ADO与JavaScript来获取受语句影响的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ADO 中使用JScript(Microsoft JavaScript方言)Windows脚本宿主脚本来更新SQL Server表。我想获取脚本中受更新影响的行数,但是JavaScript没有传递引用,因此在收到受 Command#Execute 函数的 RecordsAffected 参数。因此,我正在寻找获取该信息的最佳方法。

I'm using ADO in a JScript (Microsoft JavaScript dialect) Windows Scripting Host script to update a SQL Server table. I'd like to get the number of rows affected by the update in the script, but JavaScript doesn't have pass-by-reference and so I can't do the usual thing where I receive the records affected from the Command#Execute function's RecordsAffected argument. So I'm looking for the best way to get that info.

出于与该查询不直接相关的原因,尽管我希望避免使用存储过程意识到有效(我只是将SP中的 @@ rowcount 返回)。我正在尝试找到一种可靠但简单的非SP方法。

For reasons not related directly to this query, I want to avoid using a stored procedure for this although I realize that that would work (I'd just return @@rowcount out of the SP). I'm trying to find a reliable but simple non-SP means of doing it.

我环顾四周,发现该语句的语法如下:

I looked around and found this syntax for the statement:

UPDATE MyTable
SET MyColumn = (blah blah blah)
WHERE (blah blah blah) ;
SELECT @@rowcount as 'RowsAffected'

...这使我返回了一个-row ResultSet 包含计数。这似乎确实有效,并且在我有限的测试中似乎可以正常工作(当其他操作也正在进行时,我没有得到错误的计数,等等),但是由于某种原因,它似乎很笨拙。

...which sends me back a one-row ResultSet containing the count. That does seem to work, and in my limited testing seems to work correctly (I don't get the wrong count when other operations are also happening, etc.), but it seems...kludgy for some reason.

鉴于我列出的可能不合理的限制条件,这是最好的方法吗?跨平台解决方案不是必需的(尽管如此,欢迎您,但它总是与Microsoft SQL Server兼容的(2005 +)。

Is that the best way to do it, given the perhaps-unreasonable constraints I've listed? Cross-platform solutions are not required (welcome, though, as always), it can be Microsoft SQL Server-specific (2005+).

请先感谢。

推荐答案

不确定您为什么认为它很笨拙。这种方法没错。

Not sure why you think it's kludgy. Nothing wrong with this approach.

这篇关于如何使用ADO与JavaScript来获取受语句影响的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆