I just installed the Oracle express database and am trying to read some data from the table that I posted there:
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();
}
}
On while (reader.Read())it just shuts down, since the reader does not contain any data. What's wrong? Connectionstring? I ran the same SELECTin a commandprompt tool that is installed using Oracle express and it works great.
source
share