"No data exists for the row/column." 执行 OLEDB Oracle OleDbDataReader



我知道这是非常基本的,我已经做了数百次了。但是,出于某种奇怪的原因,我在数据库上执行这个命令,当它试图从结果中读取一列时,它失败了。如果我在以相同凭据登录的SQL Plus中执行此语句,则行(表中有1行)会被选中。你知道我做错了什么吗?我尝试按名称、索引以及任何列访问这些列——所有列都不提供数据。我尝试了不使用.NextResult()(以防万一),同样的异常。

'...
' Determine if this database is Multisite enabled
Dim multisiteCmd As OleDbCommand = DbConnection.CreateCommand
multisiteCmd.CommandText = "SELECT * FROM TDM_DB_VERSION;"
Dim dbVersionReader As OleDbDataReader = multisiteCmd.ExecuteReader()
If dbVersionReader.HasRows Then
    dbVersionReader.NextResult()
    'If a ReplicaID was generated for the Database ID, then this is part of a
    'multisite implementation
    'Dim dbRepID As String = dbVersionReader("DB_REPLICID")
    Dim dbRepID As String = dbVersionReader(9)
    PluginSettings.UseMultisite = False
    If Not dbRepID Is Nothing Then
        If dbRepID.Length > 0 Then
            PluginSettings.UseMultisite = True
            PluginSettings.MultisiteReplicaId = dbRepID
        End If
    End If
End If
dbVersionReader.Close()

正如您从这些即时命令中看到的,连接是打开的:

DbConnection.Provider"OraOLEDB.Oracle"?DbConnection.State打开{1}

NextResult()适用于具有多个结果集的语句。例如,如果您发送了这样的命令:

"SELECT * FROM TDM_DB_VERSION;SELECT * FROM dual;"

请注意,其中有两个查询。您可以通过对数据库的一个调用和一个OleDbDataReader来处理这两个问题,NextResult()就是其中的一部分。

你想要的是:

Dim multisiteCmd As OleDbCommand = DbConnection.CreateCommand
multisiteCmd.CommandText = "SELECT * FROM TDM_DB_VERSION;"
Dim dbVersionReader As OleDbDataReader = multisiteCmd.ExecuteReader()
If dbVersionReader.Read() Then
    'If a ReplicaID was generated for the Database ID, then this is part of a
    'multisite implementation
    'Dim dbRepID As String = dbVersionReader("DB_REPLICID")
    Dim dbRepID As String = dbVersionReader(9)
    PluginSettings.UseMultisite = False
    If Not dbRepID Is Nothing Then ' Do you mean check for DbNull here? "Nothing" is not the same thing
        If dbRepID.Length > 0 Then
            PluginSettings.UseMultisite = True
            PluginSettings.MultisiteReplicaId = dbRepID
        End If
    End If
End If
dbVersionReader.Close()

相关内容

  • 没有找到相关文章

最新更新