PowerShell MDB查询 - 脚本在Access中不在PowerShell中工作

时间:2018-05-24 15:05:07

标签: powershell ms-access

正如主题所说,我在Access中直接对MDB进行了查询,我有一个PowerShell脚本可以使用不同的查询,但是此查询不返回任何数据。想法?

这有效......

$path = "C:\temp\Config.mdb"
$adOpenStatic = 3
$adLockOptimistic = 3
$cn = new-object -comobject ADODB.Connection
$rs = new-object -comobject ADODB.Recordset

$cn.Open("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = $path")
$Ports = $rs.open("Select * from Options where OptionName='Eng.SerialPortMgr.PrinterPort1'",$cn,$adOpenStatic,$adLockOptimistic)
$rs.MoveFirst()

do {
$rs.Fields.Item("OptionName").value + " = " + $rs.Fields.Item("OptionData").value; 
$rs.MoveNext()} 
until($rs.EOF -eq $True)

$rs.Close()
$cn.Close()

$Ports

这不,我不明白为什么。唯一的区别是查询和此脚本中的查询可用于Access ...

$path = "C:\temp\Config.mdb"
$adOpenStatic = 3
$adLockOptimistic = 3
$cn = new-object -comobject ADODB.Connection
$rs = new-object -comobject ADODB.Recordset

$cn.Open("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = $path")
$Ports = $rs.open("SELECT Options.OptionName, Options.OptionData FROM Options WHERE OptionName LIKE 'Eng.SerialPortMgr.PrinterPort*'",$cn,$adOpenStatic,$adLockOptimistic)
$rs.MoveFirst()

do {
$rs.Fields.Item("OptionName").value + " = " + $rs.Fields.Item("OptionData").value; 
$rs.MoveNext()} 
until($rs.EOF -eq $True)

$rs.Close()
$cn.Close()

$Ports

1 个答案:

答案 0 :(得分:0)

这有效......

$path = "C:\temp\Config.mdb"
$adOpenStatic = 3
$adLockOptimistic = 3
$cn = new-object -comobject ADODB.Connection
$rs = new-object -comobject ADODB.Recordset

$cn.Open("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = $path")
$SawConfigPorts = $rs.open("SELECT Options.OptionName, Options.OptionData FROM Options WHERE OptionName LIKE 'Eng.SerialPortMgr.PrinterPort%'",$cn,$adOpenStatic,$adLockOptimistic)
$rs.MoveFirst()

do {
    $rs.Fields.Item("OptionName").value + " = " + $rs.Fields.Item("OptionData").value; 
        $rs.MoveNext() } 
        until($rs.EOF -eq $True)

$rs.Close()
$cn.Close()

$SawConfigPorts