Which code segment should you use?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft
ADO.NET. The application connects to a Microsoft SQL Server 2005 database. You write
the following code segment.
string query = “Select EmpNo, EmpName from dbo.Table_1;
select Name,Age from dbo.Table_2″;
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = command.ExecuteReader();
You need to ensure that the application reads all the rows returned by the code
segment.Which code segment should you use?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft
ADO.NET. The application connects to a Microsoft SQL Server 2005 database. You write
the following code segment.
string query = “Select EmpNo, EmpName from dbo.Table_1;
select Name,Age from dbo.Table_2″;
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = command.ExecuteReader();
You need to ensure that the application reads all the rows returned by the code
segment.Which code segment should you use?

A.
while (reader.NextResult())
{
Console.WriteLine(String.Format(“{0}, {1}”,reader[0], reader[1]));
reader.Read();
}

B.
while (reader.Read())
{
Console.WriteLine(String.Format(“{0}, {1}”,reader[0], reader[1]));
reader.NextResult();
}

C.
while (reader.Read())
{
Console.WriteLine(String.Format(“{0}, {1}”,reader[0], reader[1]));
}
reader.NextResult();
while (reader.Read())
{
Console.WriteLine(String.Format(“{0}, {1}”,reader[0], reader[1]));
}

D.
while (reader.NextResult())
{
Console.WriteLine(String.Format(“{0}, {1}”,reader[0], reader[1]));
}
reader.Read();
while (reader.NextResult())
{
Console.WriteLine(String.Format(“{0}, {1}”,reader[0], reader[1]));
}

Explanation:
http://msdn.microsoft.com/en-us/library/haa3afyz%28VS.80%29.aspx



Leave a Reply 0

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