Sql 比较While循环中相同表的表行计数和上一个表行计数
试图理解让表读取SQL表行数的基本逻辑-存储该值。 下一次表是只读的时候,如果行数增加,请执行某些操作(在本例中,将事件写入MS日志文件)。 基本上-查找已添加到帐户以触发事件的新行 while($true)的作用是使这个PowerShell脚本在后台无限期地运行—因此这是使用睡眠来间歇性地检查表状态Sql 比较While循环中相同表的表行计数和上一个表行计数,sql,powershell,Sql,Powershell,试图理解让表读取SQL表行数的基本逻辑-存储该值。 下一次表是只读的时候,如果行数增加,请执行某些操作(在本例中,将事件写入MS日志文件)。 基本上-查找已添加到帐户以触发事件的新行 while($true)的作用是使这个PowerShell脚本在后台无限期地运行—因此这是使用睡眠来间歇性地检查表状态 while($true) { ### there’s a bunch of code to make the connection and variables set before thi
while($true)
{
### there’s a bunch of code to make the connection and variables set before this:
$DataAdapter = new-object System.Data.SqlClient.SqlDataAdapter $SqlCommand
$dataset = new-object System.Data.Dataset
[void]$DataAdapter.Fill($dataset)
$DataSet.Tables[0].'Table Name'
$sqlConnection.Close()
$sqlConnection.Dispose()
### set the number of rows in table since last count
$dataset.Tables[0].Rows.Count | set-content set.txt
$LastRowCount = Get-Content set.txt #this is where I’m stuck on how to apply this last count
#do I need another loop inside?
if($dataset.Tables[0].Rows.Count -gt 0 -and $dataset.Tables[0].Rows.Count -gt $LastRowCount) {
write-Eventlog –LogName HUGs –Source Exciter –EventID 101 -Message "testing 123"
}
else{
Write-Host "NO CHANGE IN RECORD COUNT FROM LAST RUN"
}
#TAKE A FIVE MINUTE BREAK
Start-Sleep -Seconds 30
}
您需要2个变量,但我不熟悉powershell,所以这只是一些伪代码
$LastRowCount = Get-Content; // Set the variable before the loop
while($true)
{
$CurrentRowCount = Get-Content; // Get the update count
If $LastRowCount <> $CurrentRowCount then
{
write-Eventlog –LogName HUGs –Source Exciter –EventID 101 -Message "testing 123"
$LastRowCount = $CurrentRowCount // Update the variable for the next loop
} else {
Write-Host "NO CHANGE IN RECORD COUNT FROM LAST RUN"
}
$LastRowCount=获取内容;//在循环之前设置变量
while($true)
{
$CurrentRowCount=获取内容;//获取更新计数
如果$LastRowCount$CurrentRowCount,则
{
写入事件日志–日志名HUGs–源励磁机–事件ID 101–消息“testing 123”
$LastRowCount=$CurrentRowCount//为下一个循环更新变量
}否则{
写入主机“上次运行的记录计数没有变化”
}
那么问题出在哪里?不确定如何将$LastCount放入逻辑中以正确存储上一次运行的行数-这样我就可以比较last rowcount和current rowcount了?