How to use an OleDbConnection object to connect to an Oracle database : Oracle « Database ADO.net « C# / C Sharp






How to use an OleDbConnection object to connect to an Oracle database

 

using System;
using System.Data;
using System.Data.OleDb;

class OleDbConnectionOracle
{
  public static void Main()
  {
    string connectionString = "provider=MSDAORA;data source=ORCL;user id=SCOTT;password=TIGER";
    OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);

    OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();

    myOleDbCommand.CommandText = "SELECT empno, ename, sal FROM emp WHERE empno = 7369";

    myOleDbConnection.Open();

    OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();

    myOleDbDataReader.Read();

    Console.WriteLine("myOleDbDataReader[\" empno\"] = " + myOleDbDataReader["empno"]);
    Console.WriteLine("myOleDbDataReader[\" ename\"] = " + myOleDbDataReader["ename"]);
    Console.WriteLine("myOleDbDataReader[\" sal\"] = " + myOleDbDataReader["sal"]);

    myOleDbDataReader.Close();
    myOleDbConnection.Close();
  }
}
           
         
  








Related examples in the same category

1.Oracle connection string for C#
2.Connect to an Oracle server
3.Static Helper for executing SQL statements against Oracle Requires the ODP.NET provider