3rd Year Paper - 1 Unit 5
3rd Year Paper - 1 Unit 5
Data Access Using the ADO Data Control & Report Generation
Released in 1996, activeX data object (ADO) originated from the concept of RDO (remote data
object) and DAO (data access object). One of the constituents of MDAC (Microsoft data access
components), ADO and other MDAC constituents provides a framework of components used by
client applications to access SQL, semi-structured and legacy data stores.
ADO.NET is an advanced data access technology designed to work in the .NET environment and is
based on the disconnected model for data access. While ADO uses COM (Component Object Model)
technology for providing data access service from unmanaged code, ADO.NET depends on managed
providers of the CLR (Common Language Runtime) of the .NET framework.
ADO uses an OLEDB provider for connecting to the data sources and accessing data. OLEDB is a
component based programmatic interface provided to interact with different data sources. These data
sources can be both relational and non-relational databases such as object databases, web pages,
spreadsheets or e-mail messages. Prior to OLEDB and ADO, ODBC (open database connectivity) was
the popular model used in applications across platforms.
The object model of ADO contains four collections of twelve objects. The different collections are
fields, properties, parameters and errors. Each collection consists of the following twelve objects:
ADO 2.8 is the latest version and has the following features:
Components: These are used for data access and manipulation from a variety of sources to
offer benefits like ease of use, faster access, low memory overhead and a small disk footprint.
ADO MD (MultiDImensional): This is used to access multidimensional data like CubeDef
and CellSet objects.
RDS (Remote Data Services): This is for retrieval and update of data in the server from a
client in a single transaction.
ADOX (ADO Extensions): This is an additional set of components used to create and
maintain objects related to schema (tables or procedures) and security (user and group).
ADO Components
ActiveX Data Objects consists of a generic-style data-access structure that allows you to
access any data source, regardless of its structure, with the same programming interface. The
individual objects within the ADO object model are used to provide all of the data-storage,
manipulation, and retrieval commands needed when writing a data-based application. ADO
includes the following objects and collections:
In the next sections, I take a closer look at these objects and collections.
The Connection object is the gateway for all data communications through ActiveX Data
Objects. Figure 2-1 illustrates the Connection object’s object model.
In order to access data from any source, a connection for that source must first be established.
ADO uses the Connection object to accomplish this. The Connection object uses information
that you provide to establish a unique connection to a particular OLE DB data source. The
standard information that a Connection object accepts includes filenames, data-provider
names, usernames, and passwords.
Applications communicate with a database, firstly, to retrieve the data stored there and
present it in a user-friendly way, and secondly, to update the database by inserting, modifying
and deleting data.
Microsoft ActiveX Data Objects.Net (ADO.Net) is a model, a part of the .Net framework that
is used by the .Net applications for retrieving, accessing and updating data.
ADO.Net Object Model
ADO.Net object model is nothing but the structured process flow through various
components. The object model can be pictorially described as −
The data residing in a data store or database is retrieved through the data provider. Various
components of the data provider retrieve data for the application and update data.
Datasets store data in a disconnected cache and the application retrieves data from it.
Data readers provide data to the application in a read-only and forward-only mode.
Data Provider
A data provider is used for connecting to a database, executing commands and retrieving
data, storing it in a dataset, reading the retrieved data and updating the database.
This is integral to the working of ADO.Net since data is transferred to and from a
4
database through a data adapter. It retrieves data from a database into a dataset and
updates the database. When changes are made to the dataset, the changes in the
database are actually done by the data adapter.
The .Net Framework data provider for SQL Server - provides access to Microsoft
SQL Server.
The .Net Framework data provider for OLE DB - provides access to data sources
exposed by using OLE DB.
The .Net Framework data provider for ODBC - provides access to data sources
exposed by ODBC.
The .Net Framework data provider for Oracle - provides access to Oracle data source.
The EntityClient provider - enables accessing data through Entity Data Model (EDM)
applications.
DataSet
DataSet is an in-memory representation of data. It is a disconnected, cached set of records
that are retrieved from a database. When a connection is established with the database, the
data adapter creates a dataset and stores data in it. After the data is retrieved and stored in a
dataset, the connection with the database is closed. This is called the 'disconnected
architecture'. The dataset works as a virtual database containing tables, rows, and columns.
The DataSet class is present in the System.Data namespace. The following table describes all
the components of DataSet −
Sr.No. Components & Description
DataTableCollection
1
It contains all the tables retrieved from the data source.
DataRelationCollection
2
It contains relationships and the links between tables in a data set.
ExtendedProperties
3
It contains additional information, like the SQL statement for retrieving data, time of
retrieval, etc.
DataTable
4
It represents a table in the DataTableCollection of a dataset. It consists of the
DataRow and DataColumn objects. The DataTable objects are case-sensitive.
DataRelation
5
It represents a relationship in the DataRelationshipCollection of the dataset. It is used
to relate two DataTable objects to each other through the DataColumn objects.
DataRowCollection
6
It contains all the rows in a DataTable.
DataView
7
It represents a fixed customized view of a DataTable for sorting, filtering, searching,
editing and navigation.
PrimaryKey
8
It represents the column that uniquely identifies a row in a DataTable.
DataRow
It represents a row in the DataTable. The DataRow object and its properties and
9
methods are used to retrieve, evaluate, insert, delete, and update values in the
DataTable. The NewRow method is used to create a new row and the Add method
adds a row to the table.
DataColumnCollection
10
It represents all the columns in a DataTable.
DataColumn
11
It consists of the number of columns that comprise a DataTable.
Connecting to a Database
The .Net Framework provides two types of Connection classes −
Example 1
We have a table stored in Microsoft SQL Server, named Customers, in a database named
testDB. Please consult 'SQL Server' tutorial for creating databases and database tables in SQL
Server.
Select a server name and the database name in the Add Connection dialog box.
Select the Preview Data link to see the data in the Results grid −
When the application is run using Start button available at the Microsoft Visual Studio tool
bar, it will show the following window −
SQL
SQL is a database computer language designed for the retrieval and management of data in a
relational database. SQL stands for Structured Query Language. This tutorial will give you
a quick start to SQL. It covers most of the topics required for a basic understanding of SQL
and to get a feel of how it works.
SQL is Structured Query Language, which is a computer language for storing, manipulating
and retrieving data stored in a relational database.
SQL is the standard language for Relational Database System. All the Relational Database
Management Systems (RDMS) like MySQL, MS Access, Oracle, Sybase, Informix, Postgres
and SQL Server use SQL as their standard database language.
Applications of SQL
As mentioned before, SQL is one of the most widely used query language over the databases.
I'm going to list few of them here:
Structured Query Language contains the following four components in its process:
Query Dispatcher
Optimization Engines
Classic Query Engine
SQL Query Engine, etc.
A classic query engine allows data professionals and users to maintain non-SQL queries. The
architecture of SQL is shown in the following diagram:
1. CREATE command
2. UPDATE command
3. DELETE command
4. SELECT command
5. DROP command
6. INSERT command
CREATE Command
This command helps in creating the new database, new table, table view, and other objects of
the database.
UPDATE Command
This command helps in updating or changing the stored data in the database.
DELETE Command
This command helps in removing or erasing the saved records from the database tables. It
erases single or multiple tuples from the tables of the database.
SELECT Command
This command helps in accessing the single or multiple rows from one or multiple tables of
the database. We can also use this command with the WHERE clause.
DROP Command
This command helps in deleting the entire table, table view, and other objects from the
database.
INSERT Command
This command helps in inserting the data or records into the database tables. We can easily
insert the records in single as well as multiple rows of the table.
SQL vs No-SQL
The following table describes the differences between the SQL and NoSQL, which are
necessary to understand:
SQL No-SQL
1. SQL is a relational database management 1. While No-SQL is a non-relational or
system. distributed database management system.
2. The query language used in the No-SQL
2. The query language used in this database
database systems is a non-declarative query
system is a structured query language.
language.
3. The schema of SQL databases is 3. The schema of No-SQL databases is a
predefined, fixed, and static. dynamic schema for unstructured data.
4. These databases are vertically scalable. 4. These databases are horizontally scalable.
5. The database type of SQL is in the form
5. The database type of No-SQL is in the form
of tables, i.e., in the form of rows and
of documents, key-value, and graphs.
columns.
6. It follows the ACID model. 6. It follows the BASE model.
7. Complex queries are easily managed in 7. NoSQL databases cannot handle complex
the SQL database. queries.
8. This database is not the best choice for 8. While No-SQL database is a perfect option
storing hierarchical data. for storing hierarchical data.
9. All SQL databases require object- 9. Many No-SQL databases do not require
relational mapping. object-relational mapping.
10. Gauges, CircleCI, Hootsuite, etc., are
10. Airbnb, Uber, and Kickstarter are the top
the top enterprises that are using this query
enterprises that are using this query language.
language.
11. SQLite, Ms-SQL, Oracle, PostgreSQL, 11. Redis, MongoDB, Hbase, BigTable,
and MySQL are examples of SQL database CouchDB, and Cassandra are examples of
systems. NoSQL database systems.
Advantages of SQL
SQL provides various advantages which make it more popular in the field of data science. It
is a perfect query language which allows data professionals and users to communicate with
the database. Following are the best advantages or benefits of Structured Query Language:
1. No programming needed
SQL does not require a large number of coding lines for managing the database systems. We
can easily access and maintain the database by using simple SQL syntactical rules. These
simple rules make the SQL user-friendly.
A large amount of data is accessed quickly and efficiently from the database by using SQL
queries. Insertion, deletion, and updation operations on data are also performed in less time.
3. Standardized Language
SQL follows the long-established standards of ISO and ANSI, which offer a uniform
platform across the globe to all its users.
4. Portability
The structured query language can be easily used in desktop computers, laptops, tablets, and
even smartphones. It can also be used with other applications according to the user's
requirements.
5. Interactive language
We can easily learn and understand the SQL language. We can also use this language for
communicating with the database because it is a simple query language. This language is also
used for receiving the answers to complex queries in a few seconds.
The SQL language also helps in making the multiple views of the database structure for the
different database users.
Disadvantages of SQL
With the advantages of SQL, it also has some disadvantages, which are as follows:
1. Cost
The operation cost of some SQL versions is high. That's why some programmers cannot use
the Structured Query Language.
2. Interface is Complex
Another big disadvantage is that the interface of Structured query language is difficult, which
makes it difficult for SQL users to use and manage it.
The business rules are hidden. So, the data professionals and users who are using this query
language cannot have full database control.
Data Environment
Data Environment object is created and managed using Data Environment designer. A Data
Environment object can accomplish any of the following tasks.
1. Select Project-> Add Data Environment. If Add Data Environment option is not found then select
More ActiveX Designers and then select Data Environment.
Note: Visual Basic adds Data Environment Designer to your project and also creates a connection
object.
It is included in all major editions and ships in all languages available with Visual
Studio .NET. Crystal Reports .NET provides developers with the fastest, most productive
way to create and integrate presentation-quality, interactive reports that scale to meet the
demands of end users. This article introduces you to Crystal Reports .NET and shows you
how to create reports and view them in either a Windows form or a Web form. I will also
show you how to publish a report as a Web service and consume the service in a Web form.
There are a wide variety of available sources for feeding data into your report. You can use
an OLE DB provider, ODBC data source, ADO.NET dataset, and even an XML Web service.
Crystal Reports .NET is a very powerful report writer. It offers a very well defined object
model that provides flexibility when integrating reports into Windows and Web applications.
It also comes with a highly customizable viewer component that gives developers control on
how their reports are presented to users. This article examines some of the new features of
Crystal Reports .NET and shows you how to integrate a report into your application. After
creating this report, you will learn how to publish its content to the Web as a Web service.
Crystal Reports .NET has been completely re-written from the ground-up in C#. It is tightly
integrated into the Visual Studio .NET IDE. Developers no longer have to switch to a
Crystal Reports .NET provides developers with two different report viewing components.
The first can be used for displaying reports in Windows forms. The other is a component that
can be used to display reports in a Web environment. The beauty of these viewers is in their
simplicity. Viewing a report is as simple as setting the ReportSource property of the
respective viewer.
ADO.NET Integration
ADO.NET is now the lingua-franca of data interchange in the .NET world. Crystal
Reports .NET provides the ability to use ADO.NET datasets as the data source for reports.
Reports can be exposed as Web services. This adds additional power to Web service
applications. Exposing reports as Web services enables developers to offer real-time
information (in the form of a report) as opposed to real-time data!
1. 2. Display the Quantity on Hand, Unit Price, Re-order Level and value of each
product.
2. 3. Show a count and total value of all products in stock by category and an overall
count and total value.
3. 4. Highlight all products where the quantity on hand has fallen below the re-order
level.
4. 5. Limit the report products that have not been discontinued.