Working with Oracle data
provider (ADO.NET)
The .NET Framework Data
Provider for Oracle describes a collection of classes for accessing an Oracle
data source in the managed space. The System.Data.OracleClient
namespace is the .NET Framework Data Provider for Oracle. You need to add a
reference to the System.Data.OracleClient
assembly first. To add a reference to System.Data.OracleClient right
click on project in Solution Explorer and select Add Reference.
![addreference.png]()
On the Add Reference Dialog box select System.Data.OracleClient
in .NET section.
![OracleClient.png]()
Following
example shows working of Oracle data provider.
using System;
using System.Data.OracleClient;
namespace OracleDataProvider
{
class Program
{
static void Main(string[] args)
{
// Connect using .NET data provider for Oracle
string ConnectString ="Data Source=myOracleDb;User Id=sa;Password=sa1234;";
string sqlSelect = "SELECT TOP 4 ProductID, Name, ProductNumber FROM Product";
using (OracleConnection connection = new OracleConnection(ConnectString))
{
OracleCommand command = new OracleCommand(sqlSelect, connection);
// Execute the DataReader
connection.Open();
OracleDataReader reader = command.ExecuteReader();
// Output the data from the DataReader to the console
Console.WriteLine("ProductID\tProductName\t\tProductNumber\n");
while (reader.Read())
Console.WriteLine("{0}\t\t{1}\t\t{2}", reader[0], reader[1], reader[2]);
}
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
}
}
}