diff --git a/samples/dotnet-core/DataReader/DataReader.cs b/samples/dotnet-core/DataReader/DataReader.cs index 724af9ae..f86186cf 100644 --- a/samples/dotnet-core/DataReader/DataReader.cs +++ b/samples/dotnet-core/DataReader/DataReader.cs @@ -41,24 +41,24 @@ static void Main(string[] args) //"Data Source=;"; using (OracleConnection con = new OracleConnection(conString)) + using (OracleCommand cmd = con.CreateCommand()) { - using (OracleCommand cmd = con.CreateCommand()) + try { - try - { - con.Open(); - cmd.BindByName = true; + con.Open(); + cmd.BindByName = true; - //Use the command to display employee names from - // the EMPLOYEES table - cmd.CommandText = "select first_name from employees where department_id = :id"; + //Use the command to display employee names from + // the EMPLOYEES table + cmd.CommandText = "select first_name from employees where department_id = :id"; - // Assign id to the department number 50 - OracleParameter id = new OracleParameter("id", 50); - cmd.Parameters.Add(id); + // Assign id to the department number 50 + OracleParameter id = new OracleParameter("id", 50); + cmd.Parameters.Add(id); - //Execute the command and use DataReader to display the data - OracleDataReader reader = cmd.ExecuteReader(); + //Execute the command and use DataReader to display the data + using (OracleDataReader reader = cmd.ExecuteReader()) + { while (reader.Read()) { Console.WriteLine("Employee First Name: " + reader.GetString(0)); @@ -67,14 +67,13 @@ static void Main(string[] args) Console.WriteLine(); Console.WriteLine("Press 'Enter' to continue"); - reader.Dispose(); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); } - Console.ReadLine(); } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + Console.ReadLine(); } } }