閱讀我剛剛安裝了一個Oracle Express數據庫,我試圖從我已經擺在那裏一個表中讀取一些數據:問題從Oracle
using (OracleConnection conn = new OracleConnection("Data Source=localhost:1521/xe;Persist Security Info=True;User ID=SYSTEM;Password=SYSTEMPASSWORD"))
{
OracleCommand command = new OracleCommand("SELECT * FROM Persons WHERE Firstname = 'John'", conn);
conn.Open();
OracleDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
string strResult = reader.GetString(0);
}
}
catch (OracleException oex)
{
MessageBox.Show(oex.Message, "Oracle error");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
finally
{
reader.Close();
}
}
在它只是退出,因爲讀者做了while (reader.Read())
不保存任何數據。哪裏不對? Connectionstring
?我在與Oracle Express一起安裝的commandprompt工具中運行了相同的SELECT
,並且它工作正常。
您確定連接已正確打開並且ExecuteReader可以正常工作嗎?你是否在賦值之後和進入while循環之前放置了一個斷點並檢查了讀者對象的值? –
如果您將在sqlplus或任何其他工具中運行它,此選擇是否返回任何行? – igofed
嘗試不帶WHERE子句的select – Adauto