Which two actions should you perform?

You are developing an application that includes the following code segment. (Line numbers are included for
reference only.)
01 class Customer
02 {
03 public string CompanyName { get; set; }
04 public string Id { get; set; }
05 }
06 const string sqlSelectCustomerss = “SELECT CustomerID, CompanyName FROM
Customers”;
07 private static IEnumerable<Customer> GetCustomers(string sqlConnectionString)
08 {
09 List<Customer> customers = new List<Customer>();
10 SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);
11 using (sqlConnection)
12 {
13 SqlCommand sqlCommand = new SqlCommand(sqlSelectCustomers,
sqlConnection);
14
15 using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
16 {17
18 {
19 Customer customer = new Customer();
20 customer.Id = (string)sqlDataReader[“CustomerID”];
21 customer.CompanyName = (string)sqlDataReader[“CompanyName”];
22 customers.Add(customer);
23 }
24 }
25 }
26 return customers;
27 }
The GetCustomers() method must meet the following requirements:
connect to a Microsoft SQL Server database.
populate Customer objects with data from the database.
return an IEnumerable<Customer> collection that contains the populated Customer objects.
You need to meet the requirements. Which two actions should you perform? (Each correct answer presents
part of the solution. Choose two.)

You are developing an application that includes the following code segment. (Line numbers are included for
reference only.)
01 class Customer
02 {
03 public string CompanyName { get; set; }
04 public string Id { get; set; }
05 }
06 const string sqlSelectCustomerss = “SELECT CustomerID, CompanyName FROM
Customers”;
07 private static IEnumerable<Customer> GetCustomers(string sqlConnectionString)
08 {
09 List<Customer> customers = new List<Customer>();
10 SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);
11 using (sqlConnection)
12 {
13 SqlCommand sqlCommand = new SqlCommand(sqlSelectCustomers,
sqlConnection);
14
15 using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
16 {17
18 {
19 Customer customer = new Customer();
20 customer.Id = (string)sqlDataReader[“CustomerID”];
21 customer.CompanyName = (string)sqlDataReader[“CompanyName”];
22 customers.Add(customer);
23 }
24 }
25 }
26 return customers;
27 }
The GetCustomers() method must meet the following requirements:
connect to a Microsoft SQL Server database.
populate Customer objects with data from the database.
return an IEnumerable<Customer> collection that contains the populated Customer objects.
You need to meet the requirements. Which two actions should you perform? (Each correct answer presents
part of the solution. Choose two.)

A.
Insert the following code segment at line 17: while (sqlDataReader.GetValues())

B.
Insert the following code segment at line 14: sqlConnection.Open();

C.
Insert the following code segment at line 14: sqlConnection.BeginTransaction();

D.
Insert the following code segment at line 17: while (sqlDataReader.Read())

E.
Insert the following code segment at line 17: while (sqlDataReader.NextResult())

Explanation:
SqlConnection.Open – Opens a database connection with the property settings specified by the
ConnectionString. http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.open.aspx
SqlDataReader.Read – Advances the SqlDataReader to the next record. http://msdn.microsoft.com/en-us/
library/system.data.sqlclient.sqldatareader.read.aspx



Leave a Reply 0

Your email address will not be published. Required fields are marked *