powershell - IF 语句检查数据集是否为空

标签 powershell

我用这个 $SqlAdapter.Fill($DataSet) 填充我的数据集,然后将返回的结果分配给我的变量,如下所示 $rowCount = $SqlAdapter.Fill($DataSet) 然后使用 if 语句来确定 rowcount 是否 > 0 if($rowCount > 0) 但我的代码从不执行 if 语句。它在屏幕上返回从我的 .Fill 返回的 3 行,但仅此而已。完整代码如下:

$SqlAdapter.Fill($DataSet)
$rowCount = $SqlAdapter.Fill($DataSet)
if($rowCount > 0)
{
  [System.IO.Directory]::CreateDirectory("C:\Data\")
}

最佳答案

PowerShell 语法中的“大于”是 -gt。试试这个:

$SqlAdapter.Fill($DataSet)
$rowCount = $SqlAdapter.Fill($DataSet)
if($rowCount -gt 0)
{
  [System.IO.Directory]::CreateDirectory("C:\Data\")
}

This link在 PowerShell 的 if 和语法方面非常有帮助。

关于powershell - IF 语句检查数据集是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30699268/

相关文章:

Windows Server 2019 上的 Azure 管道 powershell 和 git 在输出中出现错误

powershell - 延迟忽略CTRL + C-Powershell

powershell - 将 Powershell 设置为 Vim 的 shell : command does not seem to be passed correctly

powershell - Azure Active Directory 应用程序和服务主体

powershell - 在字符串数组的开头和结尾插入引号

powershell - 如何同时捕获外部命令输出并将其打印到终端

sql - 我需要找到一种方法来删除 SQL Server 备份文件夹中第三个 .bak 文件之后的所有内容

powershell - 通过批处理将命令运行到 openssl

azure - 术语 'New-AzResourceGroupDeployment' 未被识别为 cmdlet、函数的名称

Powershell:所有新对象都不是平等的吗?