Using OracleCommand to do the query sql : Oracle « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data;
using System.Data.OracleClient;

class Class1{
    static void Main(string[] args)
    {
      string connstr = "User Id=scott; Password=tiger; Data Source=oranet";
      OracleConnection con = new OracleConnection(connstr);
      con.Open();
      string sql = "select empno, ename from emp";

      OracleCommand cmd = new OracleCommand(sql, con);
      OracleDataReader dr = cmd.ExecuteReader();
      while (dr.Read())
      {
        Console.Write(dr[0].ToString() + "\t");
        Console.Write(dr[1].ToString() + "\t");
        Console.Write(dr[2].ToString() + "\t");
        Console.WriteLine(dr[3].ToString());
      }

      // close and dispose the objects
      dr.Close();
      dr.Dispose();
      cmd.Dispose();
      con.Close();
      con.Dispose();
    }
}








32.3.Oracle
32.3.1.how to use an OleDbConnection object to connect to an Oracle database
32.3.2.A connection string using integrated security for Oracle database
32.3.3.A connection string without integrated security for Oracle database
32.3.4.Get connection state and server version
32.3.5.Using OracleCommand to do query
32.3.6.Using OracleCommand to do the query sql
32.3.7.Using OracleCommandBuilder
32.3.8.Using OracleDataAdapter
32.3.9.Using OracleDataReader to read from Oracle database
32.3.10.Using OracleParameter
32.3.11.Connect to an Oracle Database using .NET data provider for OLE DB
32.3.12.Connect to an Oracle Database using OdbcConnection
32.3.13.Connecting to an Oracle Database with OracleConnection
32.3.14.Do a delete command to Oracle database
32.3.15.Do an insert command to Oracle database
32.3.16.Do an update to Oracle database
32.3.17.Manual Loopup for Oracle database
32.3.18.Read string from OracleDataReader
32.3.19.Use OracleConnection to connect to Oracle database
32.3.20.Rollback for Oracle database
32.3.21.Runs the CustomerAdd stored procedure.
32.3.22.No Connection Pooling
32.3.23.Read decimal from OracleDataReader
32.3.24.Connection String for Oracle database