Sunday, 3 April 2011

Ado.Net basic questions

What is the namespace in which .NET has the  data functionality classes ?

Following are the namespaces provided by .NET for data management :-

System.Data: Has DataSet,DataTable, and DataRelation.

System.Data.OleDB: Has OleDbConnection, OleDbCommand, etc.

System.Data.SqlClient: SqlConnection, SqlCommand, SqlDataAdapter etc.

System.XML This Contains the basic objects required to create, read, store, write, and manipulate XML documents.

What is the use of connection object ?

They are used to connect a data to a Command object.

a. An OleDbConnection object is used with an OLE-DB provider
b. A SqlConnection object uses Tabular Data Services (TDS) with MS SQL Server

What is the use of command objects and what are the methods provided by the command object ?

Used to connect connection object with Datareader or dataset.Following are the methods provided by command object :-

a. ExecuteNonQuery :- Used for a query that does not return any rows (an UPDATE, DELETE or INSERT).Returns an Integer indicating the number of  rows affected by the query.
b. ExecuteReader :- Return a "reader" object that is connected to the resulting rowset within the database, allowing the rows to be retrieved.
c. ExecuteScalar :- Returns only a single value (effectively the first column of the first row of the resulting rowset). Any other returned column and rows are discarded.

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.

Explain ExecuteNonQuery?

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

What is the ExecuteScalar method?

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.


No comments:

Post a Comment