nerdexam
Microsoft

70-516 · Question #211

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application. The application connects to a Microsoft SQL Server 2008 database. You add the following store…

The correct answer is A. var res = command.ExecuteReader(). ExecuteReader Sends the CommandText to the Connection and builds a SqlDataReader. SqlCommand Class

Querying Data

Question

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application. The application connects to a Microsoft SQL Server 2008 database. You add the following store procedure to the database. CREATE PROCEDURE GetSalesPeople AS BEGIN SELECT FirstName, LastName, Suffix, Email, Phone FROM SalesPeople END You write the following code segment. (Line numbers are included for reference only.) 01 SqlConnection connection = new SqlConnection("..."); 02 SqlCommand command = new SqlCommand("GetSalesPeople", connection); 03 command.CommandType = CommandType.StoredProcedure; 04 ... You need to retreive all of the results from the stored procedure. Which code segment should you insert at line 04?

Options

  • Avar res = command.ExecuteReader();
  • Bvar res = command.ExecuteScalar();
  • Cvar res = command.ExecuteNonQuery();
  • Dvar res = command.ExecuteXmlReader();

How the community answered

(21 responses)
  • A
    81% (17)
  • B
    10% (2)
  • C
    5% (1)
  • D
    5% (1)

Explanation

ExecuteReader Sends the CommandText to the Connection and builds a SqlDataReader. SqlCommand Class

Topics

#SqlCommand#ExecuteReader#stored procedure#CommandType

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice