Question 3
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.
NOTE: Each correct selection is worth one point.
Insert the following code segment at line 16:
while(sqlDataReader.NextResult())
Insert the following code segment at line 13:
sqlConnection.Open();
Insert the following code segment at line 13:
sqlConnection.BeginTransaction();
Insert the following code segment at line 16:
while(sqlDataReader.Read())
Insert the following code segment at line 16:
while(sqlDataReader.GetValues())
Correct answer: BD
Explanation:
SqlConnection.Open - Opens a database connection with the property settings specified by the ConnectionString. SqlDataReader.Read - Advances the SqlDataReader to the next record. References:http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.open.aspxhttp://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.read.aspx
References:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.open.aspx
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.read.aspx