Posted Under ADO.NET Interview Questions
Can you enforce constraints and relations on tables inside a DataSet?
Yes, the collection of DataTable objects from a DataSet can relate to each other with the DataRelation objects. You can also put in execution of data integrity in the DataSet by using UniqueKeyConstraint and ForeignKeyConstraint objects.
What happens when you apply AcceptChanges() method on a DataSet?
When you will apply AcceptChanges() method to a DataSet, then it will call AcceptChanges() method on each table within the DataSet. This method will also have in both the DataRow and DataTable classes.
When AcceptChanges() calls at the DataTable level, it causes the AcceptChanges method for each DataRow.
When AcceptChanges() call on the DataSet, then the edit mode of DataRow objects will end successfully with editing. The RowState property of each DataRow also changes. The added and modified rows become as it is, and deleted rows are removed.
What is the use of DataSet.HasChanges() Method?
This method is used to made changes into the DataSet including new, modify, and delete rows. It will return a Boolean value that is either true or false according to the changes made in DataSet. This can also be used to update a DataSource, if there is some change.
What happens when you apply RejectChanges method on a DataSet?
Let's consider, a DataSet contains 3 tables. When you will apply RejectChanges() method, it will be automatically invoked on all the 3 tables in the dataset. So any changes that were done with the tables will be rolled back.
When you call DataTable.RejectChanges method, the rows that are in edit-mode will cancel their edit. It will remove the new added rows. It will also return back all modified and deleted rows to its original state.
What is the use of SqlParameter.Direction Property?
This Property is used to initialize the Sql Parameter type and sets some of its properties such as input-only , output-only , bidirectional , or a stored procedure which will return value parameter. The default property is Input.
What is Connection Pooling ?
Connection Pooling will make a single connection instance, which allows that instance to connect to all the databases. Advantage is that it does not open and close the connection object multiple times.
What is the role of data provider?
The .NET data provider layer resides between the application and the database. Its task is to take care of all their interactions.
The .NET Data provider can be demonstrated to be:
• SQL Server data provider
• OLEDB data provider
• ODBC Data Provider
ADO.NET supports the following OLE DB Providers:
• SQLOLEDB - Microsoft OLE DB Provider for SQL Server.
• MSDAORA - Microsoft OLE DB Provider for Oracle.
• Microsoft.Jet.OLEDB.4.0 - OLE DB Provider for Microsoft Jet
What is DataViewManager?
DataViewManager is used to manage view settings of the tables in a DataSet. A DataViewManager is best suited for views that consist of a combination of multiple tables. The properties like ApplyDefaultSort, Sort, RowFilter, and RowStateFilter are referenced using DataViewSetting.
Components of data providers in ADO.NET?
Connection Object: The Connection object represents the connection to the database. The Connection object has ConnectionString which contains all the information required to connect to the database.
Command Object: The command object is used to execute stored procedures and command on the database. It contains methods such as ExecuteNonQuery, ExecuteScalar and ExecuteReader.
ExecuteNonQuery: It executes a command that doesn’t return any record, such as INSERT, UPDATE and DELETE.
ExecuteScalar: It executes and returns a single value from a database.
ExecuteReader: It returns a result set by the DataReader object.
DataReader Object: It provides a connected, forward-only and read-only recordset from a database. The Command.ExecuteReader method creates and returns a DataReader object. Since it is connected to the database through out its lifetime, it requires the use of connection object.
DataAdapter Object: This object acts like a communication bridge between the database and a dataset. It fills the dataset with data from the database. The dataset stores the data in the memory and it allows changes. The DataAdapter update method can transmit the changes to the database.
What are the different DataAdapter Object properties present?
Select Command: This command is used to select the data from the database.
Insert Command: This command is used to insert a row into the table.
Delete Command: This command is used to delete the existing rows in the table.
Update Command: This command is used to update the values of records present in table.
Define connected and disconnected data access in ADO.NET?
In connected data access you can connect through the DataReader objects of data provider. This object requires exclusive use of the connection object. It can provide fast and forward-only data access. It doesn't allow editing.
Disconnected data access is achieved through the DataAdapter object. This object establishes connection, executes the command, load data in the DataSet. The Dataset works independent of database. It contains data in the memory and can edit the data. The changes in the data can be transmitted to the database using Update method of DataAdapter object.
Describe Command Type property of a SQLCommand in ADO.NET?
A SQLCommand has CommandType property which can take Text, Storedprocedure or TableObject as parameter. If it is set to Text, the command executes SQL string that is set to CommandText property. When set to StoredProcedure, the command runs the stored procedure of the database. If the property is set to TableObject, the command returns the entire content of the table indicated by the CommandText property.
Check all articles under ADO.NET Interview Questions