You are on page 1of 8

ADO.NET Difference FAQs-1 1. What are the differences between DataReader and DataAdapter? S.

No 1 2 3 4 DataReader Works in Connected Mode Can have only one record at a time Is ForwardOnly and Readonly Faster DataAdapter Works in Disconnected Mode Can have more than 1 records Can navigate front and back and editable Slower

2. What are the differences between DataSet and DataReader? S.No 1 DataSet The data store whose records have to be manipulated can be disconnected. You have the provision to cache data fetched from data store when using dataset. Dataset objects have XML Support. A single dataset object can contain collection of datatable objects wherein each datatable object refers to a table in the datastore. Hence you can manipulate on multiple tables using a dataset. Using dataset, you can read the records fetched in any order. Performance wise, dataset is slow because it has multiple tables which in turn include multiple rows, columns and constraints. DataReader You can read data from datareader only if the connection to data store exists. Caching of data is not possible.

3 4

XML Support is not provided by datareader. Datareader can read records fetched by a command object containing a single query. If you have to fetch data from multiple tables, then datareader is not advantageous when compared to dataset. While reading records, you can iterate only in forward direction. Datareader gives high performance and records can be fetched faster when compared to dataset.

5 6

3. What is the difference between DataSet.Copy() and DataSet.Clone()? S.No 1 DataSet.Copy() DataSet.Copy() copies both the structure and data DataSet.Clone() DataSet.Clone() copies the structure of the DataSet, including all DataTable schemas, relations,

and constraints and it does not copy any data 4. What are the differences between RecordSet and DataSet? S.No 1 RecordSet RecordSet provides data of one row at an instant RecordSet always needs an Open connection to read the data from data sources RecordSet is able to load the structure and data of only one table at a time RecordSet does not support constraints of Databases DataSet DataSet is a data structure which represents the complete table data at the same time DataSet needs connection only for retrieving the data. After retrieve the data connection is not necessary DataSet has the capability to store the structure and data of multiple tables at a time DataSet enforces data integrity by using Constraints

5. What are the differences between ADO and ADO.Net? S.No 1 2 3 4 5 6 ADO It is a COM based library. Classic ADO requires active connection with the data store. Locking feature is available. Data is stored in binary format. XML integration is not possible. It uses the object named Recordset to reference data from the data store. Using Classic ADO, you can obtain information from one table or set of tables through join. You cannot fetch records from multiple tables independently. Firewall might prevent execution of Classic ADO. Classic ADO architecture includes client side cursor and server side cursor. ADO.Net It is a CLR based library. ADO.NET architecture works while the data store is disconnected. Locking feature is not available. Data is stored in XML. XML integration is possible. It uses Dataset Object for data access and representation. Dataset object of ADO.NET includes collection of DataTables wherein each DataTable will contain records fetched from a particular table. Hence multiple table records are maintained independently. ADO.NET has firewall proof and its execution will never be interrupted. ADO.NET architecture doesn't include such cursors.

8 9

10

You cannot send multiple transactions using a single connection instance.

You can send multiple transactions using a single connection instance.

Reference: http://onlydifferencefaqs.blogspot.in/2012/07/adonet-difference-faqs-1.html ADO.Net Difference FAQs-2 1.Difference between Typed DataSet and Untyped DataSet S.No 1 Typed DataSet It provides additional methods, properties and events and thus it makes it easier to use. 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. We will get advantage of intelliSense in VS. NET. Performance is slower in case of strongly typed dataset. In complex environment, strongly typed dataset's are difficult to administer. Untyped DataSet It is not as easy to use as strongly typed dataset. They do not do error checking at the design time as they are filled at run time when the code executes.

3 4 5

We cannot get an advantage of intelliSense. Performance is faster in case of Untyped dataset. Untyped datasets are easy to administer.

Typed DataSets use explicit names and DataTypes for their members. ex: northwindDataSet.Products.ProductNameColumn.Caption = "pnames"; UnTyped DataSets use table and column collections for their members ex: ds.Tables["emp"].Columns["eno"].ReadOnly=true; 2.Difference between DataView and DataTable S.No 1 DataView Read-only i.e., DataView can be used to select the data. DataTable Read/Write i.e., Datatable can be used to edit or select or delete or insert a data.

Is a reference to an existing DataTable. Cannot be populated from scratch; must be instantiated with a reference to an existing DataTable. Data is a reference to an existing DataTable, and does not consume space. Can sort or filter rows without modifying the underlying data. Rows and columns can be hidden and revealed repeatedly.

Can be created empty and then populated

Data takes storage space.

Can add/edit/delete rows, columns, and data, and all changes are persistent.

5 6

Can return a DataTable version Can be cloned of the view A live reference to a DataTable; any changes in the DataTable data is immediately reflected in the view. Is source data; does not contain references

Supports calculated columns, Does not support calculated which are columns with a value columns calculated on the fly by combining or manipulating other columns. Can hide or show selected columns No row or column hiding

3.Difference between Connected and Disconnected Environment S.No 1 Connected Environment Disconnected Environment

Connected Environment needs Disconnected Environment does a constantly connection of user not need any connection. to data source while performing any operation. Only one operation can be performed at a time in connection Environment. DataReader is used in Connection Environment. It is slower in speed. Multiple operations can be performed. DataSet is used in it. Disconnected Environment has a good speed.

3 4

We get updated data in it.

There is a problem of dirty read.

Reference: http://onlydifferencefaqs.blogspot.in/2012/08/adonet-difference-faqs-2.html ADO.NET Difference FAQs-3 1.Difference between ExecuteNonQuery() and ExecuteScalar() methods in ADO.NET S.No 1 ExecuteNonQuery() ExecuteScalar()

It will work with Action Queries It will work with Non-Action Queries only that contain aggregate functions. (Create,Alter,Drop,Insert,Updat e,Delete). It returns the count of rows It returns the first row and first effected by the Query. column value of the query result. Return type is int Return type is object.

2 3 4

Return value is optional and Return value is compulsory and can be assigned to an integer should be assigned to a variable of variable. required type.

Example-1 for ExecuteNonQuery Method -Insert: SqlCommand cmd = new SqlCommand("Insert Into SampleTable Values('1','2')",con); //con is the connection object con.Open(); cmd.ExecuteNonQuery(); //The SQL Insert Statement gets executed Example-2 for ExecuteNonQuery Method - Update: public void UpdateEmployeeEmail() { SqlConnection conn = new SqlConnection(connString)) String sqlQuery = "UPDATE Employee SET empemail='umar.ali@xyz.com' WHERE empid=5; SqlCommand cmd = new SqlCommand(sqlQuery, conn); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally {

conn.Close(); } return count; } Example-1 for ExecuteScalar Method: This returns only one value that is first column value of the first row in the executed query public int getSomeProdId() { int count=0; SqlConnection conn = new SqlConnection(connString)) String sqlQuery = "SELECT COUNT(*) FROM dbo.region"; SqlCommand cmd = new SqlCommand(sqlQuery, conn); try { conn.Open(); //Since return type is System.Object, a typecast is must count = (Int32)cmd.ExecuteScalar(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { conn.Close(); } return count; } Example-2 for ExecuteScalar Method: This returns one value only, no recordsets. cmd.CommandText = "Select Name, DOB, from Emp where ID=1"; Dim strName As string = cmd.ExecuteScalar.ToString 2.Difference between ExecuteNonQuery() and ExecuteReader() methods in ADO.NET S.No 1 ExecuteNonQuery() ExecuteReader()

It will work with Action Queries It will work with Action and Nononly Action Queries (Select) (Create,Alter,Drop,Insert,Updat e,Delete).

2 3 4

It returns the count of rows It returns the collection of rows effected by the Query. selected by the Query. Return type is int Return type is DataReader.

Return value is optional and Return value is compulsory and can be assigned to an integer should be assigned to an another variable. object DataReader.

Example-1 for ExecuteNonQuery Method -Insert: SqlCommand cmd = new SqlCommand("Insert Into SampleTable Values('1','2')",con); //con is the connection object con.Open(); cmd.ExecuteNonQuery(); //The SQL Insert Statement gets executed Example-2 for ExecuteNonQuery Method - Update: public void UpdateEmployeeEmail() { SqlConnection conn = new SqlConnection(connString)) String sqlQuery = "UPDATE Employee SET empemail='umar.ali@xyz.com' WHERE empid=5; SqlCommand cmd = new SqlCommand(sqlQuery, conn); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { conn.Close(); } return count; } Example for ExecuteReader Method: Here, ExecuteReader is used to get set of records by specified query, namely, "select * from emp" SqlConnection con = new SqlConnection(constr); //constructor can be connection of string. SqlCommand cmd = new SqlCommand ("select * from emp", con); con.Open(); SqlDataReader dr = cmd. ExecuteReader (CommandBehavior. CloseConnection); //Implicitly closes the connection because CommandBehavior. CloseConnection was specified.

while(dr.Read()) { Console.WriteLine (dr.GetString(0)); } dr.Close(); Reference: http://onlydifferencefaqs.blogspot.in/2012/08/adonet-difference-faqs-3.html

You might also like