mabu mabu - 19 days ago 8
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

DataTable
:

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();
oraCon.Open();
oraDA.Fill(dt);
oraCon.Close();
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

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

[ObsoleteAttribute("OracleConnection has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260", 
    false)]
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#?