我有这个 .xls vba 代码,我试图在其中检查记录计数并基于该代码决定进一步的逻辑。
这个 vba 在 Provider = MSDAORA 上运行良好,但是当我更改为 Provider = OraOLEDB.Oracle 这个 vba 检查查询总是返回记录计数 = 0
使用 OraOLEDB.Oracle 的所有其他查询都可以正常工作。
此处附上代码。
提前感谢您在这里指出问题。
Public Function CheckJob(BusDate As String, JobName As String) As Boolean
Dim Cnt As ADODB.Connection, rst As ADODB.Recordset
Dim cmdGetComp As New ADODB.Command
Dim RecCount As Integer
Dim rng As Range
Dim StConn As String
Dim Sql As String
StConn = strETDDBConnStringADO()'This is connection string with all credentials
Set Cnt = New ADODB.Connection
Set rst = New ADODB.Recordset
Set cmdGetComp = New ADODB.Command
Sql = "Select Count(*) from XYZ_DBO.TABLE_STATUS where BUSINESS_DATE='XXXXXX'"
With Cnt
.Open (StConn)
With cmdGetComp
.ActiveConnection = Cnt ' Reference to a Connection object.
.CommandType = adCmdText
.CommandText = Sql
Set rst = .Execute() ' Set the Recordset to the results of executing the query
End With
RecCount = rst(0) 'rst(0) always return value of 0 even if manual query have 1 record
.Close
End With
If RecCount > 0 Then
CheckJob = True
Else
CheckJob = False
End If
End Function