using System.Data.OracleClient; using System; class OracleExample { static void Main() { string connectionString = "Data Source=MyOracleDB;User ID=myUsername;Password=myPassword;"; string queryString = "SELECT COUNT(*) FROM employees"; using (OracleConnection connection = new OracleConnection(connectionString)) { OracleCommand command = new OracleCommand(queryString, connection); connection.Open(); int count = (int) command.ExecuteScalar(); Console.WriteLine("There are " + count + " employees in the database."); } } }
using System.Data.OracleClient; using System; class OracleExample { static void Main() { string connectionString = "Data Source=MyOracleDB;User ID=myUsername;Password=myPassword;"; string queryString = "SELECT name FROM employees WHERE id = :id"; using (OracleConnection connection = new OracleConnection(connectionString)) { OracleCommand command = new OracleCommand(queryString, connection); command.Parameters.AddWithValue(":id", 123); connection.Open(); string name = (string) command.ExecuteScalar(); Console.WriteLine("Employee name: " + name); } } }In this example, we execute a query to retrieve the name of an employee with a specified ID. The `AddWithValue()` method is used to add a parameter to the command object with the name `":id"` and a value of `123`. The `ExecuteScalar()` method is then used to retrieve the result and assign it to the variable `name`, which is then printed to the console. The System.Data.OracleClient package library is a part of the .NET Framework Class Library.