Search code examples
asp.netoracle-databaseodp.netoracleclient

What is the alternative for System.Data.OracleClient.OracleCommand?


Can anyone share a link to sample (ASP).Net code that uses the new Oracle Data Provider.Net library?

I have code a web application code that uses the System.Data.OracleClient classes and want to migrate to the new Oracle Data Provider for .Net.

Thanks


Solution

  • Your code might look as any standard ADO.NET code and you will be using an OracleConnection:

    var connectionString = "Data Source=ORCL;User Id=user;Password=pwd;";
    
    using (var conn = new OracleConnection(connectionString))
    using (var cmd = conn.CreateCommand())
    {
        conn.Open(); 
        cmd.CommandText = "SELECT name FROM mytable";
        using (var reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                string name = reader.GetString(0);
                // TODO: process the results here
            }
        }
    }