我正在编写一个powershell函数来从我们的数据库中检索学生列表,但是返回的第一项总是记录的数量。我想不出一种方法将set nocount on合并到脚本中--有什么想法吗?
到目前为止,这个函数是:
Function CheckMIS{
$Table = new-object System.Data.DataTable
$sqlConn = new-object System.Data.SqlClient.SqlConnection("Server=blah blah")
$adapter = new-object System.Data.SqlClient.SqlDataAdapter(
"select txtSchoolID,
intSystemStatus,
txtForename, txtSurname,
txtForm
from TblPupils
where intSystemStatus = 1 ",$sqlConn)
$adapter.Fill($Table)
$sqlConn.Close()
write-output $table
}它返回一个可爱的表-但第一行总是首先记录的数量。我只需要抑制该输出。
发布于 2012-07-19 22:41:27
您可以捕获行数以供以后使用。
$rowCount = $adapter.Fill($Table) 或者干脆忽略它。
$adapter.Fill($Table) | Out-Null添加"Set Nocount On;select txtSchoolID,"...在我的测试中没有任何效果。
发布于 2012-07-19 15:11:55
您应该能够将SET NOCOUNT ON添加到您的SQL中。
即SET NOCOUNT ON select txtSchoolId, intSystemStatus, txtForename, txtSurname, txtForm from TblPupils where intSystemStatus = 1
https://stackoverflow.com/questions/11554573
复制相似问题