mabu mabu - 1 year ago 94
C# Question

Method to query data from Oracle database in C#

Currently I'm using the following method to get data from Oracle database and return it to


private static DataTable OraSelect(string cmdString)
string conString = ConfigurationManager.AppSettings["dbconnection"];
OracleConnection oraCon = new OracleConnection(conString);
OracleCommand oraCmd = new OracleCommand(cmdString, oraCon);
OracleDataAdapter oraDA = new OracleDataAdapter(oraCmd.CommandText, oraCon);
DataTable dt = new DataTable();
return dt;

Visual Studio displays the following warning: "OracleConnection has been deprecated."

I think that's not the best way to do this. Could you give me some examples about how to get data from an Oracle database with a better method?

Answer Source

Have you seen MSDN Document as it clearly says in the class definiton

[ObsoleteAttribute("OracleConnection has been deprecated.", 
public sealed class OracleConnection : DbConnection, ICloneable

Follow the link mentioned in attribute constructor parameter (Oracle and ADO.NET)

You should rather use the specific Data provider from Oracle

An Example: Connecting to Oracle Database through C#?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download