Programming in C# — Question 152
You need to write a method that retrieves data from a Microsoft Access 2013 database. The method must meet the following requirements:
✑ Be read-only.
✑ Be able to use the data before the entire data set is retrieved.
✑ Minimize the amount of system overhead and the amount of memory usage.
Which type of object should you use in the method?
Answer options
- A. DbDataReader
- B. DataContext
- C. unTyped DataSet
- D. DbDataAdapter
Correct answer: A
Explanation
The correct answer is A, DbDataReader, which is designed for read-only access to data and allows for efficient retrieval of data without requiring the entire dataset to be loaded into memory. Options B, C, and D either do not meet the read-only requirement or consume more resources than necessary, making them less suitable for this scenario.