static public void ConnectAndQuery()
{
string connectionString = GetConnectionString();
using (OracleConnection conn = new OracleConnection())
{
conn.ConnectionString = connectionString;
conn.Open();
Console.WriteLine("State: " + conn.State);
Console.WriteLine("Connection String: " + conn.ConnectionString);
OracleCommand command = conn.CreateCommand();
string sql = "SELECT * FROM users";
command.CommandText = sql;
OracleDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string myField = (string)reader["MYFIELD"];
Console.WriteLine(myField);
}
}
}
The connection is established and working open but I get IndexOutOfRangeException when trying to acquire the data from the DB. The exception is caught on
string myField = (string)reader["MYFIELD"];
I looked for info about the OracleDataReader and the command in order to understand the reader, but... does it store the data acquired in an array or any other sequence ? Why am I getting the IndexOutOfRangeException and why does the reader require an argument in the [] brackets?