0% found this document useful (0 votes)
16 views7 pages

Ado Net Dataset Dataset

Uploaded by

dhaygudesuraj261
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Ado Net Dataset Dataset

Uploaded by

dhaygudesuraj261
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

ADO.

NET QUESTIONS
1. What is an ADO.Net?
 ADO.NET is used to communicate with database for data access. We can perform all types of CRUD operations
with database using ADO.NET
 Microsoft ActiveX Data Objects (ADO).
 ADO.NET is a set of classes that can be used to interact with data sources like databases and XML files.

2. What are two important objects of ADO.Net?


 SqlDataReader and SqlDataAdapter

3. What are the namespaces used in ADO.Net to connect to a database?


 If it is sql data provider then we can use System.Data.SqlClient namespace to use important classes for ado.net
code.
 System.Data.OracleClient, System.Data.OLEDB, System.Data.ODBC

4. What are the data providers in ADO.NET framework?


 There are multiple data providers in ado.net for example System.Data.SqlClient, System.Data.OLEDB,
System.Data. OracleClient, System.Data. ODBC.
 System.Data.ODBC, System.Data.OracleClient depends on underlying DBMS we can choose data providers.
[Refer - https://www.c-sharpcorner.com/blogs/adonet-data-providers1]

5. What is DataReader Object?


 DataReader object we can use to read data from database. It reads the data in forward only direction. Using
DataReader we can parse data from each column.
 The DataReader class represents a data reader in ADO.NET.
 [Refer - https://www.c-sharpcorner.com/uploadfile/mahesh/datareader-in-ado-net/]

6. What is Dataset Object?


 Dataset is a collection of data. Dataset contains DataTable which stores data in tabular format. We can retrieve
data from each column.
 An ADO.NET DataSet contains a collection of zero or more tables represented by DataTable objects. The
DataTableCollection contains all the DataTable objects in a DataSet. A DataTable is defined in the System. Data
namespace and represents a single table of memory-resident data.

7. What is object pooling?


 Object pooling is a design pattern which helps to maintain object creation for a class. We can control number of
class instances used within application.[Refer - https://www.codeguru.com/csharp/csharp/cs_misc/object-pooling-
in-c.html]

8. What is connection pooling?


 Connection pool controls the maximum number of connections to the database. Connection pooling reuses
existing active connection with the same connection string instead of creating new connections.[Refer -
https://www.c-sharpcorner.com/uploadfile/4d56e1/connection-pooling-ado-net/]
 <connectionStrings><clear /><add name="sqlConnectionString" connectionString
="Data Source=mySQLServer;Initial Catalog=myDatabase;Integrated Security=Tru
e;Connection Timeout=15;Connection Lifetime=0;Min Pool Size=0;Max Pool Size=
100;Pooling=true;" /></connectionStrings>
9. What is Data view?
 DataView is used to create different views of the data which is stored in DataTable. It means instead of showing
all data we can show filtered data or sorted data from that DataTable.[Refer -
https://www.c-sharpcorner.com/article/dataview-in-C-Sharp/]

10. What is Data Adapter?


 DataAdapter is disconnection oriented data access model/architecture which used to fill Dataset with records
returned from database.
 Fill() method from DataAdapter class opens the connection, execute the command, copy data to datatable and
closes the connection.

11. What is the use of SqlCommand object?


 SqlCommand object we can use to prepare command. We can execute inline query or stored procedure using
SqlCommand object methods.

12. What is the difference between ADO and ADO.Net?


 ADO is a legacy technology which uses OLEDB Data provider to access data whereas ADO.NET uses different
types of data providers like SQL, Oracle etsc.

13. What are the benefits of ADO.Net?


 ADO.NET gives interoperability as it works with different types of data sources.
 ADO.NET gives scalability as it can work with increased number of clients without performance impact.
 Productivity is more using ADO.NET

14. What is the use of connection object?


 Connection object is used to establish connection with database server using connection string.
 It helps to open and close connection between application and database.

15. What are all features of ADO.Net?


 ADO.NET focuses on disconnected data.
 ADO.NET allows strongly typed language.
 ADO.NET works data source through xml.

16. What is the difference between Datareader and Dataset?


 DataReader, DataSet, DataAdapter and DataTable are four major components of ADO.NET.
 The DataSet class in ADO.Net operates in an entirely disconnected nature, while DataReader is a connection
oriented service or data access model.
 DataReader :
 DataReader is used to read the data from database and it is a read and forward only connection oriented
architecture/data access model during fetch the data from database. DataReader will fetch the data very fast when
compared with dataset. Generally we will use ExecuteReader object to bind data to dataReader.
 DataSet :
 DataSet is a disconnected orient architecture/data access model that means there is no need of active connections
during work with datasets and it is a collection of DataTables and relations between tables.
 It is used to hold multiple tables with data. You can select data form tables, create views based on table and ask
child rows over relations. Also DataSet provides you with rich features like saving data as XML, List and loading
XML data.

17. What are all components of ADO.Net data provider?


 A data provider is a set of components, such as Connection, Command, DataAdapter and DataReader.
 The Connection is the first component that talks to a data source. The Connection object establishes a connection
to a data source and works as a connection reference in Command and DataAdapter objects.

18. What are the differences between OLEDB and SqlClient Providers?
 OleDb and SqlClient are both called as Data Providers in .net
 OLEDB Provider use to connect Access , Excel etc and SqlClient use to connect with SqlServer or SqlData
File
 They are basically namespaces which contain specific classes used for connectivity and for
data handling.
OleDb is referred to as System.Data.OleDb
SqlClient is referred to as System.Data.SqlClient.
OleDb: Object linking and Embedding database.
Differences:
 OleDb is used for connecting to any database like SQL Server (For SQL Server 6.5 or lower we will have to
use OleDb), Access, Excel.We have to mention the appropriate provider to connect with the particular
database.This adds an extra layer for connetion and has performance impacts or Performance is not so faster..
 SqlClient is used for SQL Server only (for SQL Server 7.0 onwards) We do not have to mention the SQL
Server provider.
 SqlClient is faster than OleDb.

19. What are the different execute methods of Ado.Net?

ExecuteNonQuery This method executes the command specifies and returns the number of rows affected.(integer)
The ExecuteReader method executes the command specified and returns an instance of
ExecuteReader
SqlDataReader class.
This method executes the command specified and returns the first column of first row of the result
ExecuteScalar
set. The remaining rows and column are ignored.
ExecuteXMLReade This method executes the command specified and returns an instance of XmlReader class. This
r method can be used to return the result set in the form of an XML document

20. What are all the commands used with Data Adapter?
 InsertCommand , UpdateCommand , and DeleteCommand get on the adapter object.

21. What is the difference between Dataset.clone and Dataset.copy?

 DataSet.Copy copies both the structure (tables, relations etc) and the data.In other word the Copy method of the
DataSet class copies both the structure and data of a DataSet object. It returns a new DataSet object having the
same structure including all DataTable schemas, relations, and constraints and data as the existing DataSet object.

 DataSet.Clone copies only the structure of the DataSet.In other word the Clone method of the DataSet class
copies only the schema of a DataSet object. It returns a new DataSet object that has the same schema as the
existing DataSet object, including all DataTable schemas, relations, and constraints. It does not copy any data
from the existing DataSet object into the new DataSet.
22. What is the difference between Command and CommandBuilder object?
a) SQLCommand is used to execute all kind of SQL queries like DML(Insert, update, Delete) & DDL
like(Create table, drop table etc.)
b) SQLCommandBuilder object is used to build & execute SQL (DML) queries like select, insert, update &
delete.

23. Is it possible to load multiple tables in a Dataset?


 Yes! We can load multiple tables in a dataset. This is the main advantage of using a dataset.

24. Do we use stored procedure in ADO.Net?


 YES ! Using a stored procedure with ADO.NET is easy. You simply follow four steps:

1. Create a Command, and set its CommandType property to StoredProcedure.


2. Set the CommandText to the name of the stored procedure.
3. Add any required parameters to the Command.Parameters collection.
4. Execute the Command with the ExecuteNonQuery( ), ExecuteScalar( ), or ExecuteQuery( ) method (depending
on the type of output generated by the stored procedure).

25. What are the methods of XML dataset object?


Method Description

GetXml( ) Retrieves the XML representation of the data in the DataSet as a single string.

GetXmlSchema( ) Retrieves the XSD schema for the DataSet XML as a single string. No data is returned.

Reads XML data from a file or a TextReader, XmlReader, or Stream object, and uses it to
ReadXml( )
populate the DataSet. The XML document can include an inline schema.

Reads an XML schema from a file or a TextReader, XmlReader, or Stream object, and uses
ReadXmlSchema( )
it to configure the DataSet (for example, creating Constraint and DataColumn objects).

Writes the contents of the DataSet to a file or a TextWriter, XmlWriter, or Stream object.
WriteXml( )
You can choose to write the schema inline.

Writes just the XSD schema describing the contents of the DataSet to a file or
WriteXmlSchema( )
a TextWriter, XmlWriter, or Stream object.

Infers the XML schema and applies it to the DataSet by reading through an XML document
InferXmlSchema( )
supplied by a file or a TextReader, XmlReader, or Stream object.

26. What are all the different authentication techniques used to connect to MS SQL Server?
SQL Server supports two authentication modes, Windows authentication mode and mixed mode.

 Windows authentication is the default, and is often referred to as integrated security because this SQL Server
security model is tightly integrated with Windows. Specific Windows user and group accounts are trusted to log in
to SQL Server. Windows users who have already been authenticated do not have to present additional credentials.
 Mixed mode supports authentication both by Windows and by SQL Server. User name and password pairs are
maintained within SQL Server.

27. Which method is used by command class to execute SQL statements that return single value?
 SqlCommand.ExecuteScalar Method

28. Tom is having XML document and that needs to be read on a daily basis. Which method of XML object
is used to read this XML file?

Reads XML data from a file or a TextReader, XmlReader, or Stream object, and uses it to
ReadXml( )
populate the DataSet. The XML document can include an inline schema.

29. Which method in OLEDBAdapter is used to populate dataset with records?


 OleDbDataAdapter.Fill Method

Fill(DataTable, Object) Adds or refreshes rows in a DataTable to match those in an


ADO Recordset or Record object using the specified DataTable and ADO
objects.
Fill(DataSet, Object, String) Adds or refreshes rows in the DataSet to match those in an
ADO Recordset or Record object using the specified DataSet, ADO object, and
source table name.

30. Which object needs to be closed?


 SqlDataReader objects are connection oriented data access model/architecture. So they needs a open connection
with datasource. Hence, they need to be explicitly close the connection too.

31. What are different layers of ADO.Net?


The three layers are:
* Presentation Layer
* Business Logic Layer
* Data Access Layer

In short, the process works like this:


* User requests for some application data.
* The data access layer retrieves the data and is forwarded to the presentation layer via business logic layer.
Sometimes data access layer gives this data directly to presentation layer.
* Presentation layer receives the data to be displayed via business logic layer.
* The user changes the data and initiates the appropriate action (such as insert, or update).
* The business logic layer validates the data submitted by the user.
* If the data is valid it is handed over to data access layer for updating into the database.

32. What are typed and un-typed dataset?


 Typed DataSet has a Xml schema and an Untyped DataSet donot have Xml schema.
 We can insert additional columns in the type dataset but in untype we can't insert additional columns here.
Typed DataSet
1.It provides additional methods, properties and events and thus it makes it easier to use.
2.Performance is slower in case of strongly typed dataset.
3.Typed DataSets use explicit names and DataTypes for their members.
Example: northwindDataSet.Products.ProductNameColumn.Caption = "pnames";
Untyped DataSet
1.It is not as easy to use as strongly typed dataset.
2.Performance is faster in case of Untyped dataset.
3.UnTyped DataSets use table and column collections for their members.
Example: ds.Tables["emp"].Columns["eno"].ReadOnly=true;

33. Which method is used to sort the data in ADO.Net?


 You can use the DataView.Sort property to specify single or multiple column sort orders and include ASC
(ascending) and DESC (descending) parameters.
 ds.Tables["Customers"].DefaultView.Sort = "Country ASC";
 dataGrid1.DataSource = ds.Tables["Customers"];

34. Which object is used to add relationship between two Datatables?


 DataRelation class object represents a parent/child relationship between two DataTable objects. This class is
resides in a System.Data namespace.
 private void CreateRelation()
{
// Get the DataColumn objects from two DataTable objects
// in a DataSet. Code to get the DataSet not shown here.
DataColumn parentColumn =
DataSet1.Tables["Customers"].Columns["CustID"];
DataColumn childColumn =
DataSet1.Tables["Orders"].Columns["CustID"];
// Create DataRelation.
DataRelation relCustOrder;
relCustOrder = new DataRelation("CustomersOrders",
parentColumn, childColumn);
// Add the relation to the DataSet.
DataSet1.Relations.Add(relCustOrder);
}

35. Which is the best method to get two values from the database?

 See the method of SqlCommand ExecuteReader that return a SqlDataReader:


using(var command = new SqlCommand("SELECT [Value1], [Value2] FROM [ExampleTable] where
Ad_name=@adname", con))
{
command.Parameters.AddWithValue("@adname", aname);
using(var reader = command.ExecuteReader())
{
while (reader.Read())
{
imgpath1 = reader[0];
imgpath2 = reader[1];
}}}

36. What are all the classes that are available in System.Data Namespace?
 The six ADO.NET namespaces are the System.Data, System.Data.Common, System.Data.Oledb,
Microsoft.Data.Odbc, System.Data.SqlClient, and System.Data.SqlTypes.
 The System.Data namespace is the core namespace of ADO .NET. It consists of the base classes for the
ADO.NET architecture. All data providers use these classes. It defines classes that represent table, columns,
row, and datasets some common classes from this namespace DataView, DataViewManager DataSet,
DataTable, DataRow, DataColumn, and DataRelation. To use these classes in your applications, you need to
add a reference to the System.Data namespace.
 Connection, Command, DataReader, DataAdapter.
37. What is the default Timeout for SqlCommand.CommandTimeout property?
 The default value is 30 seconds. Avoid a value of 0, which indicates an indefinite wait.
public static void Main() {
string connectionString = "";
// Wait for 5 second delay in the command
string queryString = "waitfor delay '00:00:05'";
using (SqlConnection connection = new SqlConnection(connectionString)) {
connection.Open();
SqlCommand command = new SqlCommand(queryString, connection);
// Setting command timeout to 1 second
command.CommandTimeout = 1;
try {
command.ExecuteNonQuery();
}
catch (SqlException e) {
Console.WriteLine("Got expected SqlException due to command timeout ");
Console.WriteLine(e);
}
}
38. What are the classes in System.Data.Common Namespace?

 The System.Data.Common namespace contains classes shared by .NET data providers.


Classes
DBDataPermission Enables a .NET Framework data provider to help ensure that a user has a
security level adequate for accessing data.
DBDataPermissionAttribute Associates a security action with a custom security attribute.

You might also like