using Oracle.ManagedDataAccess.Client; string connString = "User Id=;Password= ;Data Source="; string query = "SELECT * FROM employees"; using (OracleConnection conn = new OracleConnection(connString)) { conn.Open(); using (OracleCommand cmd = new OracleCommand(query, conn)) { using (OracleDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { Console.WriteLine(reader.GetString(0) + ", " + reader.GetString(1)); } } } }
using System.Data; using Oracle.ManagedDataAccess.Client; string connString = "User Id=In this example, a parameterized query is used with the ExecuteReader method. An OracleConnection object is initialized with the connection string. An OracleCommand object is created and initialized with a query string and the database connection object. The Parameters property of the command object is used to add a parameter to the query string which is then set to a specific value. The ExecuteReader method is called on the command object and the result set is retrieved and printed to the console. Package Library: Oracle.ManagedDataAccess.Client;Password= ;Data Source="; string query = "SELECT * FROM departments WHERE location_id = :locationId"; using (OracleConnection conn = new OracleConnection(connString)) { conn.Open(); using (OracleCommand cmd = new OracleCommand(query, conn)) { cmd.Parameters.Add(":locationId", OracleDbType.Int32).Value = 1700; using (OracleDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { Console.WriteLine(reader.GetString(0) + ", " + reader.GetString(1)); } } } }