我怀疑字符串和处理有问题。试着阅读这里的字符串,但我很困惑。
此:
$connectionString = "Provider=IBMDA400;Data ..........;"
#
cls
$conn = New-Object system.Data.OleDb.OleDbConnection
$conn.ConnectionString = $connectionString
#
#$sql= Get-Content -Path "F6161001-sql1.txt"
$sql = "select * from f6161001 where left(bidag,3)='115'"
Write-Output $sql
$conn.Open()
$cmd = New-Object System.Data.Oledb.OledbCommand($sql,$conn)
$rdr = $cmd.Executereader()
$rdr.Read()
write-output $rdr.GetValue(0)
$conn.close()
抛出:
Exception calling "ExecuteReader" with "0" argument(s): "SQL0104: Token ,3 was not valid. Valid tokens: ) ,.
Cause . . . . . : A syntax error was detected at token ,3. Token ,3 is not a valid token. A partial list of valid tokens is ) ,. This list
assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be
valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of
the token ,3. Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to
the order of clauses. -- If the error token is <END-OF-STATEMENT>, correct the SQL statement because it does not end with a valid clause."
还尝试像这样声明$ sql:
$sql =
@"
select count(*) from f6161001 where left(bidag,3)='115'
"@