ADO.NET Interview Questions and Answers (445) - Page 3

Give Expansions of ODBC,OLE,OLE DB,ADO?

1.ODBC-Open Database Connectivity.
2.OLE-Object Linking and Embedding.
3.OLE DB-Object Linking and Embedding for Database.
4.ADO-ActiveX Data Object.
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.
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.
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 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.
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.
How to access database using ADO.Net

1. Create a connection to the database using a connection object
2. Invoke a command to create a DataSet object using an adapter object
3. Use the DataSet object in code to display or to change items in the database
4. Invoke a command to update the database from the DataSet object using an adapter object
5. Close the database connection (if you explicitly opened it)
What is the Use of Connection Object ?

Inorder to interact with any database we need a Connection . This connection enables us to know the Server Name, User-Id,Password,Database Name. These are the main requirements to connect to a Database.

So in our Connection string we provide all those above mentioned properties as parameters.

Different Connection objects : SqlConnection, OleDbConnection, OdbcConnection

. OleDbConnection object is used with an OLE-Db Provider

OleDbConnection cnn ;
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=DatabaseName;";
cnn = new OleDbConnection(connetionString);

. SqlConnection object used the Tabular Data Services (TDS) With MS Sql Server.

SqlConnection con;
con = new SqlConnection("server=SERVER NAME;user id=ID;password=PASSWORD;database=DB NAME");
SqlCommand cmd;
cmd = new SqlCommand("DB Query Here",con);

. Using the OdbcConnection , we will create an OdbcCommand. From that command we can issue a Query and create an OdbcDataReader.

OdbcConnection DbConnection = new OdbcConnection("Connection String");
OdbcCommand DbCommand = DbConnection.CreateCommand();
DbCommand.CommandText = "Db Query Here";
OdbcDataReader DbReader = DbCommand.ExecuteReader();

Which of these ADO.NET classes is an abstract class ?

NOTE: This is objective type question, Please click question title for correct answer.
Which event of the SqlConnection class can be used to retreive error information from a database ?

NOTE: This is objective type question, Please click question title for correct answer.
Which of these is the fastest way of returning the total number of sales figures from a database table?

NOTE: This is objective type question, Please click question title for correct answer.
From which Interface the sqlconnetion class is derived

IDbconnection is the interface which is exposed for SQLConnection Class. It has following types defined
> ConnectionString
> ConnectionTimeout
> Database
> State
What type of Architecture is a Dataset in .Net Framework

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories