The DataAdapter uses which of the following object to retrieve the data from database

  1. Connection

  2. Command

  3. DataReader


Correct Option: B

AI Explanation

To answer this question, we need to understand the purpose of the DataAdapter and its relationship with other objects involved in retrieving data from a database.

The DataAdapter is a part of the ADO.NET framework and is used to retrieve data from a database and populate a DataTable or a DataSet. It acts as a bridge between the database and the application.

The DataAdapter uses the following objects to retrieve data from the database:

A. Connection - The Connection object is responsible for establishing a connection to the database. It provides the necessary information, such as the database server name, credentials, and other connection parameters. The DataAdapter requires a Connection object to establish a connection to the database, but it does not directly use the Connection object to retrieve data.

B. Command - The Command object is used to execute SQL queries or stored procedures against the database. It represents a single command to be executed, such as SELECT, INSERT, UPDATE, or DELETE. The DataAdapter uses the Command object to execute the query or stored procedure and retrieve the data from the database. The Command object can be an instance of the SqlCommand, OleDbCommand, or MySqlCommand classes, depending on the database provider being used.

C. DataReader - The DataReader object provides a fast, forward-only, read-only access to the data retrieved from the database. Unlike the DataAdapter, the DataReader is used for retrieving data row by row, typically when you need to iterate over a large result set. The DataReader is not used directly by the DataAdapter to retrieve data.

Therefore, the correct answer is B. The DataAdapter uses the Command object to retrieve data from the database by executing SQL queries or stored procedures.

Find more quizzes: