Ado.net Questionl

Embed Size (px)

Citation preview

  • 7/27/2019 Ado.net Questionl

    1/6

    Ques1. Which keyword is used to accept variable number of parameters? Ans. Params keyword is used to accept variable number of parameters.Ques2. .Is it possible to load multiple tables in a Dataset? Ans. Yes, it is possible to load multiple tables in a single dataset.29. Which provider is used to connect MSAccess, Oracle, etc.? OLEDB Provider and ODBC Provider are used to connect to MS Access and Oracle. OData Provider is also used to connect exclusively for oracle database.Ques3. Difference between OLEDB Provider and SqlClient?Ans. With respect to usage, there is no difference between OLEDB Provider and SqlClient. The difference lietheir performance. SqlClient is explicitly used to connect your application to SQL server directly, OLEDBProvider is generic for various databases, such as Oracle and Access including SQL Server.Ques4. ADO.NETAns. ADO.NET is a very important feature of .NET Framework, which is used to work with data that is storestructured data sources, such as databases and XML files. The following are some of the important features ADO.NET:Contains a number of classes that provide you with various methods and attributes to manage thecommunication between your application and data source.Enables you to access different data sources, suchas Microsoft SQL Server, and XML, as per your requirements.Ques5. fundamental objects in ADO.NET ? Ans. Datareader and DatasetQues6. Can you give a overview of ADO.NET architecture ? Ans. The most important section in ADO.NET architecture is Data Provider. Data Provideprovides access to data source (SQL SERVER, ACCESS, ORACLE).Connection.Command object(This is the responsible object to use stored procedures)Data Adapter(This object acts as a bridge between datastore and dataset).Datareader(This object reads data from data store in forward only mode).Ques7. How can you clear a Data from all the table in the dataset?Ans. using Dataset.Clear() method you can clear all the data from DataSetQues8. what is mean by Dataset?Ans. It is an in-Memory cache of data retrieved from Data Source.Ques9. What is the difference between Execute Reader, Execute Scalar and Execute Non Query methods?Ans. Execute ReaderExecute Reader will be used to return the set of rows, on execution of SQL Query or Stored procedure usingcommand object.Execute ScalarExecute Scalar will be used to return the single value, on execution of SQL Query or Stored procedure usingcommand object.Execute Non Query

    If the command or stored procedure performs INSERT, DELETE or UPDATE operations, then we use ExecNon Query method. Execute Non Query method returns an integer specifying the number of rows inserted,deleted or updated.Ques10. What are the different steps to access a database through ADO.NET?Ans. Create a connection to the database using a connection object.Open the Database Connection.Invoke a command to create a Dataset object using an adapter object.Use the Dataset object in code to display data or to change items in the database.Invoke a command to update the database from the Dataset object using an adapter object.Close the database connection.

  • 7/27/2019 Ado.net Questionl

    2/6

    Ques11. What are the Benefits of ADO.Net?Ans. ADO.Net offers following BenefitsInteroperability:XML Format is one of the best formats for Interoperability.ADO.NET supports to transmit the data using Xformat.

    Scalability:ADO.NET works on Dataset that can represent a whole database or even a data table as a disconnected objeand thereby eliminates the problem of the constraints of number of databases being connected. In this wayscalability is achieved.

    Performance:The performance in ADO.NET is higher in comparison to ADO that uses COM marshalling.

    Programmability:ADO.Net Data components in Visual studio help to do easy program to connect to the database.Ques12. What is Microsoft ADO.NET?Ans. ADO.NET is one of the component in the Microsoft.NET framework which contains following featuresWindows, web and distributed applications.

    i. Data Access to the applications from Database in connected (Data reader object) and disconnected (Data sand data table) model.ii. Modify the data in database from application.Ques13. What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?Ans. SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased fromMicrosoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access andInformix, but it's a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is adeprecated layer provided for backward compatibility to ODBC engines.Ques14. Difference between Association rule mining and frequent itemset miningAns. An association rule is something like "A,B ? C", meaning that C tends to occur when A and B occur. Anitemset is just a collection such as "A,B,C", and it is frequent if its items tend to co-occur. The usual way to for association rules is to find all frequent itemsets and then postprocess them into rulesQues15. Named out assemblies and corresponding namespace of all .Net framework data provider.Ans. a) .Net Framework Data Provider for SQL ServerAssembly Name :- System.Data.dllNameSpace :- System.Data.SqlClientb) .Net Framework Data Provider for OLE DB Server

    Assembly Name :- System.Data.dllNameSpace :- System.Data.OleDbC) .Net Framework Data Provider for ODBCAssembly Name :- System.Data.ODBCD) .Net Framework Data Provider for OracleAssembly Name :- System.Data.OracleClient.dllNameSpace :- System.Data.OracleClientQues16. What are different .Net framework data provider.Ans. The Four main types of .net framework data provider area) .Net framework data provider for SQL server.

  • 7/27/2019 Ado.net Questionl

    3/6

    b) .Net framework data provider for OLEDBc) .Net framework data provider for ODBCd) .Net framework data provider for Oracle.Ques17. List out Some feature of ADO.net Ans. The Key feature of ADO.Net area) Disconnected Data Architectureb) Data cached in datasetsc) Scalabilityd) Data transfer in XML format.Ques18. What is Difference between SqlCommand and SqlCommandBuilder Ans. SQLCommand is used to execute all kind of SQL queries like DML(Insert, update,Delete) & DDL like(table, drop table etc) where asSQLCommandBuilder object is used to build & execute SQL (DML) queries like select, insert, update & deQues19. What is the Use of Connection Object ? Ans. In order to interact with any database we need a Connection . This connection enables us to know theServer Name, User-Id,Password,Database Name. These are the main requirements to connect to a Database.So in our Connection string we provide all those above mentioned properties as parameters.Different Connection objects : SqlConnection, OleDbConnection, OdbcConnection. OleDbConnection object is used with an OLE-Db ProviderOleDbConnection cnn ;connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DatabaseName;";cnn = new OleDbConnection(connetionString);. SqlConnection object used the Tabular Data Services (TDS) With MS Sql Server.SqlConnection con;con = new SqlConnection("server=SERVER NAME;user id=ID;password=PASSWORD;database=DB NAMSqlCommand cmd;cmd = new SqlCommand("DB Query Here",con);. Using the OdbcConnection , we will create an OdbcCommand. From that command we can issue a Query create an OdbcDataReader.OdbcConnection DbConnection = new OdbcConnection("Connection String");OdbcCommand DbCommand = DbConnection.CreateCommand();DbCommand.CommandText = "Db Query Here";OdbcDataReader DbReader = DbCommand.ExecuteReader();

    Ques20. What is the use of dataview? Ans. Data view is used to sort and find data in a data table.Ques21. What is the use of data adapter?

    Ans. These objects connect one or more Command objects to a Dataset object. They provide logic that wouldget data from the data store and populates the tables in the Dataset, or pushes the changes in the Datasetback into the data store.. An OleDbDataAdapter object is used with an OLE-DB provider. A SqlDataAdapter object uses Tabular Data Services with MS SQL Server.Ques22. What are the two fundamental objects in ADO.NET?Ans. Data reader and Dataset are the two fundamental objects in ADO.NET.Ques23. What are the benefits of ADO.NET?Ans. BENEFITS OF ADO.NET

  • 7/27/2019 Ado.net Questionl

    4/6

    1>Scalability:-ADO.NET works on DataSet that can represent a whole database or even a data table as a disconnected objeand thereby eliminates the problem of the constraints of number of databases being connected. In this wayscalability is achieved.

    2>Data Source Independence:-In ADO.NET DataSet is completely independent of data source and no way DataSet is controlled by the datsource as it happens in case of RecordSet.

    3>Interoperability:-As ADO.NET transmits the data using the format of XML which is not dependent on ADO.NET or windowplatform.

    4>Strongly Typed Fields:-It supports strongly typed fields by using CTS.

    5>Performance:-The performance in ADO.NET is higher in comparison to ADO that uses COM marshalling.

    6>Firewall:As in ADO.NET transmission is via XML format, therefore it can pass through firewalls.Ques24. What is GetSchemaTable() in ADO.NETAns. The GetSchemaTable method returns a DataTable property that contains the column schema for aDataReader. The DataTable contains one row for each field in the resultset. Each column maps to a propertythe field in the resultset. The ColumnName property of the DataTable column is the name of the field'sproperty, such as the ColumnName, DataType, ColumnSize, IsKeyColumn, or IsAutoIncrement property. Tvalue of the DataTable column is the value of the field's property, such as the FirstName value for theColumnName property.Ques25. ado VS ado.NetAns. *)ado is connected mode always where as ado.net isconnected as well as disconnected.*)ado ---recordset whereas ado.net ---dataset*)ado---c,c++whereas ado.net---- .net framework*)ado--server based whereas ado.net clientQues26. What is Dataset?Ans. A DataSet is Disconnected Architecture,means their is no need to always open & close connection.it is

    cache of data retrieved from database.it is made up of collection of datatable.Dataset can be Typed &UnTyped usually,datasets are typed in Visual basic.A typed dataset is dataset which derived from dataset cla& uses information in XML schema file(XSD file).An untyped dataset has no built in schema.it can containtables,column & rows.but those are exposed only as collectionsQues27. What is the default TimeOut for a SqlCommand.CommandTimeout property?Ans. The default timeOut is 30 seconds.

    If you want to increase the TimeOut see the below example codeFor example:-

  • 7/27/2019 Ado.net Questionl

    5/6

    SqlCommand cmd = new SqlCommand("select * from tablename", conn);

    cmd.CommandTimeout = 50;

    SqlDataReader dr = cmd.ExecuteReader();Ques28. What is a DataSet?Ans. The Dataset is the central object in ADO.NET. DataSet is a nogical container of data. It represents a set data tables referenced as one unit in the application.

    With this object you can get all the data you need from each table quickly, examine and change it while youare disconnected from the server and then update the server with changes in an efficient operation.Ques29. How to fill DataSet with data?Ans. To fill DataSet with data we have to use Fill() method of DataAdapter object.

    Fill() has several overloads. But the simple one is[CODE]Fill(DataSet, DataTable)[/CODE]The first parameter will take the name of the dataset to be filled and the second parameter specifies the namof the DataTable in the DataSet which will contain the data.Ques30. what is difference Between datareader and dataset ?Ans. DataReader===========DataReader is like a forward only recordset. It fetches one row at a time so very less network cost compare tDataSet(Fethces all the rows at a time). DataReader is readonly so we can't do any transaction on them.DataReader will be the best choice where we need to show the data to the user which requires no transactionAs DataReader is forward only so we can't fetch data randomly. .NET Data Providers optimizes the datareadto handle huge amount of data.

    Dataset=======DataSet is an in memory representation of a collection of Database objects including tables of a relationaldatabase schemas.DataSet is always a bulky object that requires a lot of memory space compare to DataReader. We can say ththe DataSet is a small database because it stores the schema and data in the application memory area.DataSet fetches all data from the datasource at a time to its memory area. So we can traverse through theobject to get the required data like querying database.Ques31. What are the differences between ADO and ADO.NET?Ans. ADO relied on a connection based model. In the connected approach, the client had to be connected wit

    the server and remain connected till the whole procedure or transaction was completed. Time resources andbandwidth became major constraints on such architecture.

    To solve this problem the latter version of ADO used RecordSet. All the contents from the data source werecopied into RecordSet. This allows clients to get disconnected from the server, work on the RecordSet andcopy the changes back to the data source again. This approach did not succeed much because it requires COmarshalling to transmit disconnected data, it support only those datatypes that were defined by the COMstandards and hence required type conversion.

  • 7/27/2019 Ado.net Questionl

    6/6

    ADO.NET can be used to access data sources using new .NET data providers as well as existing OLEDB daproviders using the OLEDB.NET data provider.Ques32. What are the components of .NET DataProvider?Ans. The .NET DataProvider is a set of components that includes the Connection, Command, DataReader anDataAdapter objects. It is used for connecting to a database , executing commands and retrieving results.Using the .NET data provider we can either access database directly or use the disconnected approach. For tdisconnected approach we use DataSet class.

    Connection Object:-It is used to connect to the data source. Data source can be any database file. Theconnection object contains information like the provider name, server name, datasource name, user nameand password.

    Command Object:- It is used for connect the connection object to a DataReader or DataAdapter object. Thecommand object allow us to execute SQL statement or a stored procedure in a data source.

    DataReader Object:- It is used to read the data in a fast and efficient manner from the database. It is generallused to extract one or a few records or specific field values or to execute simple SQL statement.

    DataAdapter Object:- It is used to fill data from the database into the DataSet object. it is use din thedisconnected approach.Ques33. Which method do you invoke on the DataAdapter control to load your generateddataset with data?Ans. System.Data.Common.DataAdapter.Fill(System.Data.DataSet);Ques34. What is the use of DataSet?Ans. DataSet acts as a virtual table. The value is retrieved from the database and stores in the DataSet. Thenwe can pass the data to the DataGrid through DataSet.Ques35. What is Dataview in ADO Dot Net ?Ans. The DataView provides different views of the data stored in a DataTable. That is we can customize theviews of data from a DataTable. DataView can be used to sort, filter, and search the data in a DataTable ,additionally we can add new rows and modify the content in a DataTable.

    We can create DataView in two ways. Either we can use the DataView constructor, or we can create areference to the DefaultView property of the DataTable.

    DataView dView = new DataView(dTbl);dView = dataSet.Tables(0).DefaultView;Ques36. Name the classes are found in System.Data.Common NameSpace?

    Ans. 1)DataColumnMapping2)DataTableMappingQues37. Name the classes that are contained in System.Data NameSpace?Ans. DataSetDataTableDataColumnDataRowDataRealationConstraint