Frequently Asked Interview Questions

Interview Questions on ADO.NET

Interview questions on ADO.NET
ADO.NET is an integral part of .Net Framework, providing access to relational, XML, application data.
  1. System.Data.SqlClient: It describes a collection of classes used to access a SQL Server database.
  2. System.Data.OleDb: It describes a collection of classes used to access an OleDb data source. (Microsoft Access, MySQL, Informix, DB2, Oracle.. It uses OleDB drivers to connect to data source)
  3. System.Data.Odbc: It describes a collection of classes that are used to access a ODBC data source. (We can connect any relation database which supports odbc drivers).
  4. System.Data.OracleClient: It describes a collection of classes that are used to connect Oracle Database.
Create Connection
Create connection to data source; here I am using sql connection.
SQLConnection con= new SQLConnection(“datasource=localhost;database=Northwind; Integrated Security=true”)
Create command
SQLCommand cmd = new SQLCommand(“select * from Products”,con);
Execute command
Use either connected/disconnected architecture, Here I am using connected data model using DataReader.

SqlDataReader reader;
Con.open();
reader = cmd.ExecuteReader();
Close connection
Finally close the connection.
Con.Close();
SqlClient provides classes that are highly optimized to connect sql server using .Net. SqlClient data provider is faster than any other data provider in Ado.Net. It is faster because it connect sql data source directly using native library.
They are used to connect a data to a command object.
  • SqlConnection: used to connect Sql Server.
  • OleDbConnection: used to connect with OLE-DB provider.
  • OdbcConnection: is used to connect with data sources with ODBC provider.
Command object is used to connect connection object to DataReader or DataSet, to execute query against data source.
  • ExecuteNonQuery: Executes the command defined in the CommandText property against the connection defined in the Connection property 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.
  • ExecuteReader: Executes the command defined in the CommandText property against the connection defined in the Connection property. Returns a "reader" object that is connected to the resulting rowset within the database, allowing the rows to be retrieved.
  • ExecuteScalar: Executes the command defined in the CommandText property against the connection defined in the Connection property. Returns only a single value (effectively the first column of the first row of the resulting rowset). Any other returned columns and rows are discarded
DataAdapter objects can connect one or more command objects to DataSet. They provide login that gets the data from the datastore and populates the tables in the DataSet,or pushes the changes in the DataSet back into the data store.
DataReader Vs DataAdapter.
  • DataReader provde read only and forward only data access.
  • DataReader can increase application performance and reduce system overhead.
  • DataReader is connection oriented where as Data Adapter is disconnected.
  • DataReader we have to open and close connection explicitly where as if we use DataAdapter the connection is automatically opened and closed.
No, you must explicitly close the connection by calling Close or Dispose.

Most Visited Pages

Home | Site Index | Contact Us