2014-09-05 54 views
0

我知道這是非常基本的,我已經完成了數百次。但是,由於一些奇怪的原因,我在數據庫上執行這個命令,並且當它試圖從結果中讀取一列時失敗。如果我在SQL Plus中以相同憑證登錄時執行此語句,那麼行(表格有1行)被選中就好了。任何想法我做錯了什麼?我嘗試通過名稱,索引,甚至任何列來訪問列 - 他們都沒有提供任何數據。我嘗試沒有.NextResult()(以防萬一),同樣的例外。「行/列不存在數據」。執行OLEDB Oracle OleDbDataReader

'... 
' 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 Open {1}

回答

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() 
+0

是啊,我想通了這一點,並剛剛回來更新!謝謝你Joel! – 2014-09-05 17:32:30

+0

我不知道多重結果集,這似乎很強大。因此,NextResult將帶您到下一個結果集,並使用Read來遍歷每個集合中的記錄? – 2014-09-05 17:34:13

+0

這是正確的。 – 2014-09-05 18:33:36