Ado.net Interview Questions and Answers
Question - 21 : - What is Ref Cursor in .NET and how it is link with ExecuteReader ?
Answer - 21 : - Ref cursor play its role when doing with the oracle database these comes in ODP.NET. Ref Cursors are objects that link to Oracle server-side cursors.These Ref Cursor can be converted in oracle datareader with this Ref cursor we can get result with query written to pl/sql and the result can be get in .net.Now the question arise why we use Ref Cursor when we have an option of ExceuteReader reson is simple when we need more query in pl/sql means our work is done in pl/sql then we need this ref cursor for getting result set because doennot have direct connection to that table.Becasue advantage of pl/sql we can take two opertion in one query.
Question - 22 : - Define different execute methods of ADO.NET command object ?
Answer - 22 : - ExecuteScalar:- This method returns a single value from the first row and first column of the result get from the execution of SQL query.
ExecuteNonQuery:- This method executes the DML SQL query just like insert, delete or update and then returns the number of rows affected by the action.
ExecuteReader:- This method returns DataReader object which is a forward-only resultset.
ExecuteXMLReader:- This method is available for SQL Server 2000 or later. Upon execution it builds XMLReader object from standard SQL query.
Question - 23 : - Why is ADO.NET serialization slower than ADO ?
Answer - 23 : - ADO uses binary serialization while ADO.NET uses text based serialization. Since the text takes more space, it takes longer to write it out.
Question - 24 : - Is XML is a component of ADO.NET ?
Answer - 24 : - The answer of this question is always Yes because XML is an important component of ADO.NET architecture .ADO.NET use XML to store and transfer data.We not have to convert data to XML format.Datasets helps XML to integrate with ADO.NET. XML schema plays a role to get table definition,column,datatypes and constraints helps DataSet.
Question - 25 : - How to check if the Dataset has records ?
Answer - 25 : - if ds.Tables(0).Rows.Count= 0 then
'No record
else
'record found
Question - 26 : - What is the significance of CommandBehavior.CloseConnection ?
Answer - 26 : - To avoid having to explicitly close the connection associated with the command used to create either a SqlDataReader or and OleDbDataReader, pass the CommandBehavior.CloseConnection argument to the ExecuteReader method of the Connection.
dr= cmd.ExecuteReader(CommandBehavior.CloseConnection);
The associated connection will be closed automatically when the Close method of the Datareader is called. This makes it all the more important to always remember to call Close on your datareaders.
Question - 27 : - What is Dataset and Diffgram?
Answer - 27 : - When sending and retrieving a DataSet from an XML Web service, the DiffGram format is implicitly used. Additionally, when loading the contents of a DataSet from XML using the ReadXml method, or when writing the contents of a DataSet in XML using the WriteXml method, you can select that the contents be read or written as a DiffGram. For more information, see Loading a DataSet from XML and Writing a DataSet as XML Data. While the DiffGram format is primarily used by the .NET Framework as a serialization format for the contents of a DataSet, you can also use DiffGrams to modify data in tables in a Microsoft SQL Server™ 2000 database.
Question - 28 : - What are good ADO.NET object(s) to replace the ADO Recordset object?
Answer - 28 : - There are alot...but the base once are SqlConnection, OleDbConnection, etc...
Question - 29 : - What is DataSet in ADO.NET?
Answer - 29 : -
- The DataSet is a collection of database tables(row and column format) that contain the data. It is helpful for fetching the data without any need for Data Source interaction, that is why it is called a disconnected data access method.
- It is an in-memory data store that can contain multiple tables at the same time. DataRelation objects can be used to relate these tables.
- For creating a DataSet object, ADO.NET provides a DataSet class that consists of constructors and methods to carry out data-related operations.
- It can be used with various data sources, with XML data, or to manage the application’s local data. The DataSet will include related tables, data constraints, and relationships among the tables.
Question - 30 : - Give the differences between ADO and ADO.NET.
Answer - 30 : -
ADO | ADO.NET |
It is Component Object Modelling(COM) based. | It is Common Language Runtime(CLR) based. |
It works in connected mode to access the data store. | It does require an active connection, works in disconnected mode to access the data store. |
It uses the RecordSet object to access and store data from the data sources. | It uses a DataSet object to access and store data from the data sources. |
It provides a feature of locking. | It does not provide a feature of locking. |
Data is stored in binary form. | Data is stored in XML. |
It does not support XML integration. | It supports XML integration. |
Using a single connection instance, it is not possible to send multiple transactions. | Using a single connection instance you can send multiple transactions. |
We can create only client-side cursors. | Both client-side and server-side cursors can be created. |
It supports sequential row access in a RecordSet. | Non-sequential data access is supported in DataSet by using a collection-based hierarchy. |
It will make use of SQL JOINs and UNIONs for combining data from multiple tables. It is not possible to fetch records from multiple tables independently. | It will make use of DataRelational objects to combine data from multiple tables without the help of JOINs and UNIONs. Therefore records from multiple tables are maintained independently. |