PrepAway - Latest Free Exam Questions & Answers

Which code segment should you insert at line 16?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft
ADO.NET. The application uses Microsoft SQL Server 2005.You write the following code
segment. (Line numbers are included for reference only.)
01 String myConnString = “User
02 ID=<username>;password=<strong password>;Initial
03 Catalog=pubs;Data Source=myServer”;
04 SqlConnection myConnection = new
05 SqlConnection(myConnString);
06 SqlCommand myCommand = new SqlCommand();
07 DbDataReader myReader;
08 myCommand.CommandType =
09 CommandType.Text;
10 myCommand.Connection = myConnection;
11 myCommand.CommandText = “Select * from Table1; Select * from Table2;”;
12 int RecordCount = 0;
13 try
14 {
15 myConnection.Open();
16
17 }
18 catch (Exception ex)
19 {
20 }
21 finally
22 {
23 myConnection.Close();
24 }
You need to compute the total number of records processed by the Select queries in the
RecordCount variable.Which code segment should you insert at line 16?

PrepAway - Latest Free Exam Questions & Answers

A.
myReader = myCommand.ExecuteReader();
RecordCount = myReader.RecordsAffected;

B.
while (myReader.Read())
{
//Write logic to process data for the first result.
}
RecordCount = myReader.RecordsAffected;

C.
while (myReader.HasRows)
{
while (myReader.Read())
{
//Write logic to process data for the second result. RecordCount = RecordCount + 1;
myReader.NextResult();
}
}

D.
while (myReader.HasRows)
{
while (myReader.Read())
{
//Write logic to process data for the second result. RecordCount = RecordCount + 1;
}
myReader.NextResult();
}


Leave a Reply