You are developing an application that includes the following code segment. (Line numbers
are included for reference only.)
The GetAnimals() method must meet the following requirements:
Connect to a Microsoft SQL Server database.
Create Animal objects and populate them with data from the database.
Return a sequence of populated Animal 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 16:
while (sqlDataReader.NextResult())
B.
Insert the following code segment at line 13:
sqlConnection.BeginTransaction();
C.
Insert the following code segment at line 13:
sqlConnection.Open();
D.
Insert the following code segment at line 16:
while (sqlDataReader.Read())
E.
insert the following code segment at line 16:
while (sqlDataReader.GetValues())
Ans. CD
3 and 53 almost the same.
The last line says “return customers”. There is no customers variable defined.
Answer is C and D.
Reason is:
The connection object was initialized but it needs to be opened in order to execute any SQL query.
After executing, Read() method is used for fetching the each values.
c d