You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 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. (Click the Exhibit button.)
You add the following code segment to query the first row of the ProductCatalog table. (Line
numbers are included for reference only.)
01 using (var 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 var id = reader.GetInt32(0);
10
11 reader.Close();
12 }
13 }
You need to read the values for the Weight, Price, and Status columns. Which code segment should
you insert at line 10?
A.
var weight = reader.GetDouble(1);
var price = reader.GetDecimal(2);
var status = reader.GetBoolean(3);
B.
var weight = reader. GetDecimal (1);
var price = reader. GetFloat (2);
var status = reader.GetByte(3);
C.
var weight = reader.GetDouble(1);
var price = reader.GetFloat(2);
var status = reader.GetBoolean(3);
D.
var weight = reader.GetFloat(1);
var price = reader.GetDouble(2);
var status = reader.GetByte(3);