2012-07-19 126 views
1

我正在写一个powershell函数来检索我们的数据库中的学生列表,但返回的第一个项目始终是记录数。我无法想出一种方法将设置的nocount纳入脚本 - 任何想法?Powershell和SQL Server - 设置nocount

功能到目前为止是:

​​3210

它返回一个可爱的表 - 但是,第一行是永远的记录数第一。 我只需要抑制那个输出。

回答

0

您应该可以将SET NOCOUNT ON添加到您的SQL中。

SET NOCOUNT ON select txtSchoolId, intSystemStatus, txtForename, txtSurname, txtForm from TblPupils where intSystemStatus = 1

+1

加一个; SET NOCOUNT ON之后 – 2012-07-19 12:18:36

1

你可以赶上供以后使用的行数。

$rowCount = $adapter.Fill($Table) 

或者只是忽略它。

$adapter.Fill($Table) | Out-Null 

添加“Set Nocount On; select txtSchoolID”,...在我的测试中没有任何影响。