ADO.NET: 'IDataReader' to 'OracleDataReader' casting error
523187Apr 15 2008 — edited Apr 21 2008Hello everyone. Am using ADO.NET to connect to an Oracle Lite 10g Release 3 database from a C# .net compact framework based application running a WM 5.0 PPC Emulator.
Am selecting a value from a the database based on a user specified parameter but i get an error on compilation. Here is the code.
OracleConnection conn = new OracleConnection ("DSN=SALESORDER; uid = system; pwd=john" );
try
{
conn.Open();
OracleCommand cmd = (OracleCommand)conn.CreateCommand();
cmd.CommandText = "SELECT company_name FROM customers WHERE company_name =' " + textBox1.Text + " ' ";
OracleDataReader res = (OracleDataReader)cmd.ExecuteReader();
while (res.Read())
{
textBox1.Text = res.GetString(0);
}
res.Close();
}
catch (OracleException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
On compilation, i get this error:
Error 1 Cannot implicitly convert type 'System.Data.IDataReader' to 'Oracle.DataAccess.Lite.OracleDataReader'. An explicit conversion exists (are you missing a cast?)
What could i be missin or how could i redo the code to achieve same results. Kindly assist.
Ken