Working with ADO.NET Oracle Data Provider

Working with Oracle data provider (ADO.NET)
 
The .NET Framework Data Provider for Oracle provides 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.

  1. using System;  
  2. using System.Data.OracleClient;  
  3. namespace OracleDataProvider  
  4. {  
  5. class Program  
  6. {  
  7. static void Main(string[] args)  
  8. {  
  9. // Connect using .NET data provider for Oracle  
  10. string ConnectString ="Data Source=myOracleDb;User Id=sa;Password=sa1234;";  
  11. string sqlSelect = "SELECT TOP 4 ProductID, Name, ProductNumber FROM Product";  
  12. using (OracleConnection connection = new OracleConnection(ConnectString))  
  13. {  
  14. OracleCommand command = new OracleCommand(sqlSelect, connection);  
  15. // Execute the DataReader  
  16. connection.Open();  
  17. OracleDataReader reader = command.ExecuteReader();  
  18. // Output the data from the DataReader to the console  
  19. Console.WriteLine("ProductID\tProductName\t\tProductNumber\n");  
  20. while (reader.Read())  
  21. Console.WriteLine("{0}\t\t{1}\t\t{2}", reader[0], reader[1], reader[2]);  
  22. }  
  23. Console.WriteLine("\nPress any key to continue.");  
  24. Console.ReadKey();  
  25. }  
  26. }  
  27. }