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

What is the use of SqlCommandBuilder?

It is a class defined by System.Data.SqlClient namespace and is used to generate commands(insert,delete,update) that can be used

to reflect DataSet changes back to a sql server database

Update method of SqlDataAdapter uses the SqlCommandBuilder's commands
to reflect DataSet changes back to a sql server database.


//save a record in a database using the Update method of SqlDataAdapter
using System.Data;
using System.Data.SqlClient;

class dd
static void Main()
SqlConnection cn=new SqlConnection("server=.;uid=sa;pwd=1234;database=employee");
SqlDataAdapter da=new SqlDataAdapter("select * from emp",cn);
DataTable dt=new DataTable();
//emp has 2 columns known as eno and ename.

//Initialize the SqlCommandBuilder.
SqlCommandBuilder cd=new SqlComandBuilder(da);

//create a DataRow
DataRow dr=dt.NewRow();
//the row is temporarily saved

//save the Row permanently

Differences between SqlCommand and SqlDataAdapter.

1) Represents a Transact-SQL statement or stored procedure to
execute against a SQL Server database.
2)It can be initalized by any T-SQL satement
3)we have to explicitly initalize SqlDataReader when we use SqlCommand
4)database connections have to be manually opened and closed.

1)Represents a set of data commands and a database connection that
are used to fill the DataSet/DataTable and update a SQL Server database.
2)It can be initialized using Select command either directly in its constructor
or by assigning an object of SqlCommand containing a select statement
to its SelectCommand property.

3)SqlDataReader is internally used in SqlDataAdapter.
4)database connections are automatically opened and closed.
What are the Differences between OleDb and SqlClient ?

OleDb and SqlClient are both called as Data Providers in .net

They are basically namespaces which contain specific classes used for connectivity and for

data handling.

OleDb is referred to as System.Data.OleDb

SqlClient is referred to as System.Data.SqlClient

OleDb: Object linking and Embedding database.


OleDb is used for connecting to any database like SQL Server, Access, Oracle, Excel.
We have to mention the appropriate provider to connect with the particular database.
This adds an extra layer for connetion and has performance impacts.

SqlClient is used for SQL Server only. (for SQL Server 7.0 onwards)
We do not have to mention the SQL Server provider.
For SQL Server 6.5 or lower we will have to use OleDb

SqlClient is faster than OleDb.
What is the difference between Typed and UnTyped DataSets?

1)Typed DataSets use explicit names and DataTypes for their members.
northwindDataSet.Products.ProductNameColumn.Caption = "pnames";

2)They have .xsd file (Xml Schema definition) file associated with them and do error checking regarding their schema at design time using the .xsd definitions.

UnTyped DataSets:
1)UnTyped DataSets use table and column collections for their members

2)They do not do error checking at the design time as they are filled at run time when the code executes.
What is the difference between a toolstrip drop-down button and a toolstrip split button? What is the use of toolstrip container?

The difference between these two is that a toolstrip split button is a combination of two controls that is a push button and a drop-down button where a toolstrip drop-down is a single control.

Basically this is used to contain controls such as ToolStrip, MenuStrip, and statusStrip, so that these controls can be docked and moved at the run time.
Which of these is a connected architecture?

NOTE: This is objective type question, Please click question title for correct answer.
Differences between DataSet and DataReader

Differences of DataSet and DataReader:


1)DataSet is always disconnected from the database.

2)DataSet is like a memory resident database.

3)DataSet can contain temporary tables (DataTables), temporary Views(DataViews), temporary primary keys, temporary Foreign keys

4)DataSet supports forward, backward data navigation.

5)DataSets is used to return data from web service methods since it can be serialized.

6)It can be added in a ToolBox

7)Built in XML support.


1)DataReader is connected with database(connected architecture)

2)DataReader is likw a forward only cursor used for reading data.

3)DataReader has no temporary tables, views etc,

4)It supports only forward data navigation.

5)It is not returned from web service method as it cannot be searialized.

6)cannot be added in toolbox

7)No built in XML features.
Which provider ADO.NET uses by default?

There is no default provider in ADO.NET.
Providers are the namespaces defining the classes for connectivity, providing
queries,Data Reading
We have to mention the provider like System.Data.SqlClient
or System.Data.OleDb in the top of the code window.
Difference between LINQ to SQL and ADO.NET


1)Used for data handling with SQL Server databases only.

2)Uses the extension methods of System.Linq.Queryable class.

3)Introduced in .net Framework 3.0

4)DataContext is used for Database connectivity.

5)Syntax and coding is somewhat complex.

6)Uses Entity classes.


1)Used for data handling with any database: SQL Server/Access/Oracle/Excel etc.

2)Does not use the extension methods of System.Linq.Queryable class.

3)There since the .net Framework 1.0

4)SqlConnection/OleDbConnection are used for database connectivity

5)Easier syntax and coding.

Note: Both LINQ TO SQL and ADO.NET have connexted/disconnected modes of data

How can you sort a DataSet?

DataView provides us with the Sort property


 private void button1_Click(object sender, EventArgs e)

DataView dv = new DataView(ds.Tables["demo"]);
dv.Sort = "productname";
dataGridView1.DataSource = dv;



ds is the object reference of the DataSet
"demo" is the DataTable an stores a copy of the poducts table from the
Northwind database.
This example will sort the DataGridView on the basis of productname column.
first we have to connect using SqlConnection and use SqlDataAapter for the
Which of these namespaces deals with SQL Server mobile databases?

NOTE: This is objective type question, Please click question title for correct answer.
Which of these objects must be there when storing data in a disconnected state?

NOTE: This is objective type question, Please click question title for correct answer.
Which parameters define the database server in the connection string?

These are the parameters which define the database server through its name or IP address. We can use any one of them.
1) Data Source
2) server
3) addr
4) address
5) network address
What is the name of the data source when we use SQL Server Express Edition?

It is specified in the connection string.
The complete connection is like this:

Data Source=.\SQLEXPRESS;AttachDbFileName=c:\abc.mdf;Integrated Security=True;
User Instance=True

It is presumed that abc.mdf file exists in c drive. abc.ldf must also be there.
Integrated Security is used to authenticate SQL Server Express Edition.
User Instance=true. It starts SQL Server Express Edition using the current user's
Which data-related class do you use to help prevent SQL injection attacks?

NOTE: This is objective type question, Please click question title for correct answer.
What is the difference between OLEDB Provider and SqlClient ? Which is more productive to use for Dot Net application?

Generally SQLClient .NET classes are highly optimized for the .net / sqlserver combination which in-turn gives accurate results. The SqlClient data provider is fast. It works faster than the Oracle provider, and even more faster than accessing database through the OleDb layer.

Reason for being faster is, it access the native library which generally gives you a better performance and it has also got a lot of support from SQL Server team online.
what are the benefit of Stored procedure ?

1) Improved Performance : Database can optimize the data access plan used by procedure and cache it for subsequent reuse.

2) Security : Stored proceudre can be individually secured within the database. A client can be granted permissions to execute SP without having any permission on the underlying tables.

3) Easy to maintain : easier to modify a stored procedure than it is to change a hard-coded sql statement.

4) Reduce network traffice : Sql statement can be executed in batches rather than sending multiple requests from the client
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