ADO.NET Interview Questions and Answers - Part 4

19. How can you identify whether or not any changes are made to the DataSet object since it was last loaded?

The DataSet object provides the following two methods to track down the changes: The GetChanges() method - Returns the DataSet object, which is changed since it was loaded or since the AcceptChanges() method was executed. The HasChanges() method - Indicates if any changes occurred since the DataSet object was loaded or after a call to the AcceptChanges() method was made. If you want to revert all changes since the DataSet object was loaded, use the RejectChanges() method.

20. What is the use of the CommandBuilder class?

The CommandBuilder class is used to automatically update a database according to the changes made in aDataSet. This class automatically registers itself as an event listener to the RowUpdating event. Whenever data inside a row changes, the object of the CommandBuilder class automatically generates an SQL statement and uses theSelectCommand property to commit the changes made in DataSet. OLEDB provider in .NET Framework has the OleDbCommandBuiider class; whereas, the SQL provider has theSqlCommandBuilder class.

21. Explain the architecture of ADO.NET in brief?

AD0.NET consists of two fundamental components: The DataSet, which is disconnected from the data source and does not need to know where the data that it holds is retrieved from.
The .net data provider, which allows you to connect your application to the data source and execute the SQL commands against it. The data provider contains the Connection, Command, DataReader, and DataAdapter objects. TheConnection object provides connectivity to the database. The Command object provides access to database commands to retrieve and manipulate data in a database. The DataReader object retrieves data from the database in the readonly and forward-only mode. The DataAdapter object uses Command objects to execute SQL commands. The DataAdapter object loads the DataSet object with data and also updates changes that you have made to the data in the DataSet object back to the database.

22. Describe the disconnected architecture of ADO.NET's data access model?

ADO.NET maintains a disconnected database access model, which means, the application never remains connected constantly to the data source. Any changes and operations done on the data are saved in a local copy (dataset) that acts as a data source. Whenever, the connection to the server is re-established, these changes are sent back to the server, in which these changes are saved in the actual database or data source.

23. What are the pre-requisites for connection pooling?

The prerequisites for connection pooling are as follows: There must be multiple processes to share the same connection describing the same parameters and security settings. The connection string must be identical.

24. What are the usages of the Command object in ADO.NET?

The following are the usages of the Command object in AD0.NET:

  • The Command object in AD0.NET executes a command against the database and retrieves a DataReader orDataSet object.
  • It also executes the INSERT, UPDATE, or DELETE command against the database.
  • All the command objects are derived from the DbCommand class.
  • The command object is represented by two classes: SqlCommand and OleDbCommand.
The Command object provides three methods to execute commands on the database:
  • The ExecuteNonQuery() method executes a Transact-SQL statement against the connection and returns the number of rows affected.
  • The ExecuteScalar() method returns a single value from a database query.
  • The ExecuteReader() method returns a result set by using the DataReader object.

1 2 3 4 5 6