Which code segment should you use?

You have a SqlDataReader object named productsDataReader. The productsDataReader object contains three columns in the following order:

ProductID as Integer
ProductName as nvarchar(40)
UnitsInStock as Integer

You want to use productsDataReader to create an inventory management report. You define the following three variables:

int myProductID;
string myProductName;
int myUnits;

You need to ensure that the report runs as quickly as possible.

Which code segment should you use?

You have a SqlDataReader object named productsDataReader. The productsDataReader object contains three columns in the following order:

ProductID as Integer
ProductName as nvarchar(40)
UnitsInStock as Integer

You want to use productsDataReader to create an inventory management report. You define the following three variables:

int myProductID;
string myProductName;
int myUnits;

You need to ensure that the report runs as quickly as possible.

Which code segment should you use?

A.
myProductID = (int) productsDataReader[1];
myProductName = (string) productsDataReader[2];
myUnits = (int) productsDataReader[3];

B.
myProductID = (int) productsDataReader[0];
myProductName = (string) productsDataReader[1];
myUnits = (int) productsDataReader[2];

C.
myProductID = (int) productsDataReader[“ProductID”];
myProductName = (string)
productsDataReader[“ProductName”];
myUnits = (int) productsDataReader[“UnitsInStock”];

D.
myProductID = (int)
productsDataReader.GetOrdinal(“ProductID”);
myProductName = (string)
productsDataReader.GetOrdinal(“ProductName”);
myUnits = (int)
productsDataReader.GetOrdinal(“UnitsInStock”);



Leave a Reply 0

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