70-516 · Question #39
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. The database includes a database…
The correct answer is A. var weight = reader.GetDouble(1). See the full explanation below for the reasoning.
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. The database includes a database table named ProductCatalog as shown in the exhibit:
You add the following code segment to query the first row of the ProductCatalog table. (Line numbers are included for reference only.) 01 using(SqlConnection cnx = new SqlConnection(connString) 02 { 03 var command = cnx.CreateCommand(); 04 command.CommandType = CommandType.Text; 05 command.CommandText = "SELECT TOP 1 * FROM dbo.ProductCatalog"; 06 cnx.Open(); 07 var reader = command.ExecuteReader(); 08 if (reader.Read()) 09 { 10 var id = reader.GetInt32(0); 11 ... 12 reader.Close(); 13 } 14 } Which answer belongs in line 11?
Options
- Avar weight = reader.GetDouble(1);
- Bvar weight = reader.GetFloat(1);
- Cvar weight = reader.GetDouble(1);
- Dvar weight = reader.GetFloat(1);
How the community answered
(24 responses)- A75% (18)
- B8% (2)
- C13% (3)
- D4% (1)
Community Discussion
No community discussion yet for this question.