TOP ADO.NET Interview Questions and Answers

Read Latest ADO.NET Interview Questions and Answers for Freshers, 2+ Years Experienced Q and A with Explanation PDF.

What is ADO.NET?

ADO.NET is a part of the Microsoft .NET Framework. This framework provides the set of classes that deal with data communication between various layers of the software architecture and the database. It provides a continuous access to different data source types such as SQL Server versions 7, 2000, 2005. It also provides connectivity options to data sources through OLE DB and XML. Connectivity may be established with other databases like Oracle, MySQL etc. as well.
ADO.NET has the ability to separate data access mechanisms, data manipulation mechanisms and data connectivity mechanisms.
ADO.NET introduces along with it the disconnected architecture. In a disconnected architecture, data may be stored in a DataSet. It contains providers for connecting to databases, commands for execution and retrieval of results.
The classes for ADO.NET are stored in the DLL System.Data.dll.

Why ca not we use Multiple inheritance and garbage collector paralelly in .net?

.net doesn’t support the mutiple inheritance, perhaps you may talk about multi-level inheritance.

In the later case, if a class is inherited from another class, at the time of creating instance, it will obviously give a call to its base class constructor (ie bottom – top approach). Like wise the constructor execution is takes place in top down approach (ie. base class constructor is executed and the derived class constructor is executed).

So for GC, it will collect only when an object does not have any reference. As we see previously, the derived is constructed based on base class. There is a reference is set to be. Obviously GC cannot be collected.

Difference between SqlCommand and SqlCommandBuilder?

a) SQLCommand is used to execute all kind of SQL queries like DML(Insert, update,Delete) & DDL like(Create table, drop table etc)
b)SQLCommandBuilder object is used to build & execute SQL (DML) queries like select, insert, update & delete.

why edit is not possible in repeater?

It has no such feature.

Does SQLClient and OLEdb class share the same functionality?

No, each have its own functionality,
ex : for sql client , there is SqlConnection object
and for oledb client , there is OleDBConnection

What is the difference between data reader and data set?

1) DataSet is disconnected object type. It uses XML to store data.
2) It fetches all data from the data source at a time
3) Modifications can be updated to the actual database
4) It will reduce the application performance.

What is the difference between data reader and data adapter?

DateReader is an forward only and read only cursor type if you are accessing data through DataRead it shows the data on the web form/control but you can not perform the paging feature on that record(because it’s forward only type). Reader is best fit to show the Data (where no need to work on data)DataAdapter is not only connect with the Databse(through Command object) it provide four types of command (InsertCommand, UpdateCommand, DeleteCommand, SelectCommand), It supports to the disconnected Architecture of .NET show we can populate the records to the DataSet. where as Dataadapter is best fit to work on data.

what are the advantages and disadvantages of using datalist?

Adv: the DataList’s display is defined via templates,DataList allows for much more customization of the rendered HTML markup , by which it is more user-friendly displays of data.

adding such functionality with the DataList takes more development time than with the DataGrid, as,

1. The Edit/Update/Cancel buttons that can be created in a DataGrid via the EditCommandColumn column type, must be manually added to the DataList, and

2. The DataGrid BoundColumn column types automatically use a TextBox Web control for the editing interface, whereas with the DataList you must explicitly specify the editing interface for the item being edited via the EditItemTemplate.

3. we can’t do the paging and sorting with datalist controls.

What is Partial class?

A Partial class is a class that can be split into two or more classes. This means that a class can be physically separated into other parts of the class within the same namespace. All the parts must use the partial keyword. All the other classes should also have the same access modifier. At the compile time, all the partial classes will be treated as a single class. Let us list some advantages of having partial classes.

How do you connect to SQL Server Database without using sqlclient?

you can connect sql using oledbname space .

What are the steps to connect to a database?

1. Create a connection. This requires a connection string, which can be given declaratively or put in a well defined place like the .config files. Advantage of keeping in .config files is that it enables use of Connection Pooling by .Net framework, else even one small change in connection string will cause CLR to think it’s not the same connection and will instantiate new connection for other request.
2. Open the connection and keep it open until done, typically done as using (con) { //use }
3. If using connected data model, create a SqlCommand object, decorate it with desired command, command type (stored procedure for eg), add any parameters and their values to the command, and then consume the command by using ExcuteReader or ExecuteScalar. In case of ExecuteReader, we will get back a handle to a fast-forward, read only pointer to the recordset. We can also decorate Command object with multiple recordsets in 2.0 and execute one by one (MARS – Multiple Active Record Sets)
4. If using disconnected data model, create a DataAdapter object, decorate it with desired SELECT, INSERT, UPDATE, DELETE commands, add parameters as necessary and then fill up a DataSet or DataTable using the DataAdapter. Subsequent SQL can be executed using insert, update, delete commands on the dataset.

How do you update a Dataset in ADO.Net and How do you update database through Dataset?

a. Update a dataset;
Dataset ds = new dataset();
SqlDataAdapter adp = new SqlDataAdapter(Query,connection);
Again you can add/update Dataset as below
SqlDataAdapter adp1 = new SqlDataAdapter(Query1,connection);

b. Update database through dataset.
SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);
Foreach(datarow dr in ds.table[0].rows)
Dr[“column Name”] = “value”;

What is Delegate?

Delegate is an important element of C# and is extensively used in every type of .NET application. A delegate is a class whose object (delegate object) can store a set of references to methods.

What is connection String?

connection String – a string which contains address of the database we want to connect to.

How can we load multiple tables in to Dataset?

DataSet ds=new DataSet();

SqlDataAdapter dap=new SqlDataAdapter(Select * from <tablename>,<connection1>);


SqlDataAdapter dap1=new SqlDataAdapter(Select * from <tablename>,<connection1>);


Which one of the following objects is a high-level abstraction of the Connection and Command objects in ADO.NET?

DataReader DataSet DataTable DataView DataAdapter

Answer: DataAdapter

What is the ExecuteScalar method?

// Summary:

Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

// Returns:

The first column of the first row in the result set, or a null reference (Nothing in Visual Basic) if the result set is empty.

Explain ExecuteNonQuery?

// Summary:

// Executes a Transact-SQL statement against the connection and returns the number of rows affected.

// Returns:

// The number of rows affected.

How can i retrieve two tables of data at a time by using data reader?

Data reader read and forward only, how is it possible to get 2 tables of data at a time?
yes this is possible

If we execute 2 select command either in stored procedure or in select command and then executereader method fired of command object. it return 2 tables in datareader.

like :
string str=”Select * from a;select * from b”;
Now it return 2 tables in datareader (dr).

If we are not returning any records from the database, which method is to be used?

There is a method called Execute Non Query. This method executes the Update, Delete etc. This does not return any rows but will give the number of rows affected.

Can we do database operations without using any of the objects?

No its not at all possible.

can we connect two dataadapters to same data source using single connection at same time?

yes,we can connect two dataadapters to same datasource using single connection at same time.
There is a technology in 2.0 called MARS usinng Mars in connection string we can do it.
for eg:
cn.ConnectionString = “server=(local); database=employee; integrated security=sspi; MultipleActiveResultSets=True”;


Popular posts from this blog

TOP Agile Testing Interview Questions and Answers

Latest Agile Testing Interview Questions and Answers

Most Asked Agile Testing Interview Questions and Answers