Which code segment should you use?

You have a SqlDataReader object named ordersDataReader. This object contains a column named OrderQuantity as an integer value. This object also contains one row for each order received during the previous week. You need to write code that will process each row in ordersDataReader and pass OrderQuantity to a function named myFunction. Which code segment should you use?

You have a SqlDataReader object named ordersDataReader. This object contains a column named OrderQuantity as an integer value. This object also contains one row for each order received during the previous week. You need to write code that will process each row in ordersDataReader and pass OrderQuantity to a function named myFunction. Which code segment should you use?

A.
long weeklyOrderQuantity = 0;
while (ordersDataReader.Read()) {
myFunction((int)ordersDataReader[“OrderQuantity”]);
}

B.
long weeklyOrderQuantity = 0;
while (ordersDataReader.NextResult()) {
myFunction((int)ordersDataReader[“OrderQuantity”]);
}

C.
long weeklyOrderQuantity = 0;
int orderCount = 0;
while (orderCount < ordersDataReader.FieldCount) {
myFunction((int)ordersDataReader[“OrderQuantity”]);
orderCount++;
ordersDataReader.Read();
}

D.
long weeklyOrderQuantity = 0;
int orderCount = 0;
while (orderCount < ordersDataReader.FieldCount) {
myFunction((int)ordersDataReader[“OrderQuantity”]);
orderCount++;
ordersDataReader.NextResult();
}



Leave a Reply 0

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