开发者

Test if objRecordSet exists. In Powershell

My script is connecting to a MS Access Database using $objRecordSet / Microsoft.Jet.OLEDB.4.0. And then deleting something with SQL command. In t开发者_如何转开发he end I want to check if the object in the Database was really deleted. And there is my problem.

The code I am using: `

$Pathtest="H:\Dokumente\Datenbank\test.csv"
$CsvContant=import-csv -path $Pathtest -Delimiter ";"
$strDB="H:\Dokumente\Datenbank\fdms18.mdb"
$strTable="Services"
$objCon=New-Object -comobject ADODB.Connection
$objRecordSet=New-Object -comobject ADODB.Recordset
$objCon.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = $strDB")

foreach ($item in $CsvContant){
 
 $ID = $item.ID

$objRecordSet.Open("SELECT * FROM example WHERE exampleID=$ID",$objCon,3,3)
$objRecordSet.delete()

$objRecordSet.close()

$objRecordSet.Open("SELECT * FROM example WHERE exampleID=$ID",$objCon,3,3)

if ($objRecordSet -eq $null){
    write-host("It dont exist")
}

}

$objCon.close()

`

And this part don't work `

if ($objRecordSet -eq $null){
    write-host("It dont exist")
}

`

I hope some powershell genius, know how to solve my problem. Thanks in advance.

PS: My code runs on powershell x86 because i didnt want to install another framework.

~Luca

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜