Skip to content

improve usage of using blocks #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions samples/dotnet-core/DataReader/DataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ static void Main(string[] args)
//"Data Source=<service name alias>;";

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));
Expand All @@ -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();
}
}
}
Expand Down