Monday, 9 April 2018

011 ADO.Net Interview Question and Answer Part 2


1)How to Convert DataSet to DataReader ?

    ADO.NET table content a method CreateDataReader ,  you can convert a table to a DataReader.


DataTableReader dr=ds.Table[1].CreateDataReader();



Example


namespace ConsoleApplication1
{
           class Program
            {
                      static void Main(string[] args)
                       {
                        DataSet ds = new DataSet();
                        DataTable dt = new DataTable();

                       dt.Columns.Add("Name");
                       DataRow nr1 = dt.NewRow();
                       nr1["Name"] = "John1";
                       dt.Rows.Add(nr1);


                       DataRow nr2 = dt.NewRow();
                       nr2["Name"] = "John2";
                       dt.Rows.Add(nr2);

                      ds.Tables.Add(dt);

                     DataTableReader dr = ds.Tables[0].CreateDataReader();

                     while (dr.Read())
                      {
                           Console.WriteLine("Name=" + dr[0].ToString());
                       }

                     dr.Close();
                    Console.ReadKey();
                   }
            }
}
Output :
Name=John1
Name=John2

2)Which is fast , DataReader or DataSet ?

               DataReader is fast in compared to the DataSet. Internally Dataset  use DataReader to retrieve the data.

3)What is DAO ?


               DAO  stands for data access object. Data access Technology from Microsoft to access database like  Microsoft Access etc. It was introduced in Microsoft Visual Basic. It was connection oriented and need an active connection till the end.DAO is capable to handle local and remote database and also capable to perform insert ,update, delete  operation.

4)What is maximum pool size of a connection pool ?

               The maximum connection pool size is 100 by default. If you try to open connection more than pool size, connection Timeout error will be Occur.

5)What are the namespace used in ADO.NET ?

System.Data : This namespace provide  the basic classes for data access and manipulation. For example DataSet, datatable, DataView  comes under this lenses.

System.Data.Common :  This namespace also provide some basic functionality related to the data access and manipulation. DataAdaptor, dbconnection  classes comes under this namespace.

System.Data.Oledb : This namespace provide the classes for accessing  Microsoft Access, Microsoft Excel, Oracle etc. This namespace provide classes for OLEDB  connection,OLEDB command etc.

System.Data.SQLclient : This namespace provide the classes for accessing data Microsoft SQL server 7.0 and upper version. Namespace provides classes for SQL connection,SQL commands etc.

System.Data.Sqltype : This name space provide classes , that are quite similar to the .Net Framework variables, but quite familiar to SQL server. These classes are alternative to the .Net Framework variables, but more faster and safer. For example SqlBytes ,SqlChar,SqlFilestream etc.

6)What is
Databinding ?
 

             Databinding  is a method  to bind a data source with a control. The control will be populate, with the data from data source.  For example, bind gridview with datatable,  gridview rows and columns will be automatically populated. You do not need to add rows and columns programmatically. If you bind dropdownlist with a data source, the dropdownlist will be populated automatically no need to add item in it.Most of the asp.Net control support databinding. 

7)Which is the object, get data from data source fast and quick ?

            DataReader  is a component of.Net framework, which fetch data from data source fast and quick. Another technique is DataSet set to fetch data using DataAdapter. DataSet internally use data reader to fetch data . Data reader is a component to fetch data from a  database, it is the fastest.

7)What is ExecuteScalar ?

           A command  is executed against  a connection. Command  maybe  store procedure or a SQL query. After execution command , a complete set of data or single value on all can be return. When it is expected that is single value will be returned , ExecuteScalar is used. If more than one value is return, say it the Datatable is returned,  the first row and the first column of the Datatable will be considered,  rest will be discarded. If null value is returned, it will throw an error.ExecuteScalar  suitable for  agree gate for calculating function  like sum,multiply,average etc.

8)What is ExecuteNonQuery ?
 

A command  is fire against a connection .The command  may  contain SQL statement of stored procedures . ExecuteNonQuery  is used, it is expected that no results it will be returned after the command  execution. It is most commonly used and very popular  execution type.ExecuteNonQuery  returns number of rows affected by the query.

9)What is DataSet copy method ?
 

DataSet copy method , make a exact copy of a database  from another database.

DataSet ds1 = new DataSet();
DataSet ds2;
ds2 = ds.Copy();

copy is done bye  copying rows and columns and corresponding data,  data relation, table relation and schema from the source database to the database. It is actually clone of a source database.

10) What  is DataSet, haschanged  method ?

A DataSet have multiple table , rows and columns. It is very difficult  to detect any change is made in rows column of data.
DataSet.Haschanged()  method help ask to detect any change have been  made in the DataSet or not.
 


DataSet ds = new DataSet();
if (ds.HasChanges())
{
return;
}



This method return and indicating value if there is  any change  made in the DataSet after it has been last loaded.

11) What is disconnected data in ADO.Net ?


                   ADO.NET use DataSet , DataAdopter , Connection string  to retrieve data from database.DataAdopter takes  connection information, SQL statement  and create a channel in encrypted format to retrieve data from database.This data is filled to DataSet. DataSet hold multiple tables , rows columns and corresponding data ,DataSet  also holds  relationship schema  of the respective tables and data. This is called disconnected data,  a copy of data  in the DataSet  with SQL schema  is considered as disconnected data.

13)What are the various method  to generate and read XML ?

a)ReadXML()
b)GetXML()
c)WriteXML()

14)What is the use of System.Xml namespace ?

This  namespace provide the classes for read ,write, delete XML.System. XmlNode ,XmlAttribute  and many class to manipulate and details operation of XML file is managed .

No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...