SlideShare una empresa de Scribd logo
1 de 25
Developing Database Applications Using ADO.NET and XML
Rationale


                Business applications need to manage voluminous data.
                Data is generally stored in a relational database in the form
                of related tables or is stored in text format in XML
                documents. Most business applications allow users to
                retrieve the data stored in a database and present it in a
                user-friendly interface without writing the database
                commands. ADO.NET is a model used by .NET applications
                to communicate with a database for retrieving, accessing,
                and updating data. This module will provide the necessary
                skills to the students to work as a database application
                developer in the industry.




     Ver. 1.0                     Session 1                          Slide 1 of 25
Developing Database Applications Using ADO.NET and XML
Prerequisites


                A student registering for this module should be able to
                perform the following tasks:
                   Work with XML
                   Work with SQL queries




     Ver. 1.0                      Session 1                          Slide 2 of 25
Developing Database Applications Using ADO.NET and XML
Case Study - Tebisco


                Brief History
                   Tebisco is a leading producer and distributor of snacks in the
                   U.S., as well as in most of the company’s 23 international
                   markets. In 1998, consumers spent $9.2 billion on Tebisco’s
                   snacks, $1.4 billion more than in the previous year.
                   Tebisco started as a small bakery in Round Rock, Texas in
                   1978. In a short time, its gingersnaps, macaroons, shortbread
                   and other cookies were popular all over the U.S. Three years
                   ago, the management embarked on a rapid expansion plan.
                   They set up offices in Asia and Europe, in addition to
                   strengthening their U.S. operations.
                   Tebisco has got a centralized database management system
                   whereby the information about all the HR activities is
                   maintained.



     Ver. 1.0                      Session 1                               Slide 3 of 25
Developing Database Applications Using ADO.NET and XML
Objectives


                In this session, you will learn to:
                   Understand the ADO.NET object model
                   Create and manage connections




     Ver. 1.0                      Session 1             Slide 4 of 25
Developing Database Applications Using ADO.NET and XML
Understanding ADO.NET


               Business applications allow users to retrieve data from a
               database by presenting data in a user-friendly interface.
               User need not remember the database commands for
               retrieving or updating data in the database.
               Microsoft has created a family of data access technologies
               to help programmers build efficient applications to access
               data, regardless of its source.
               The guidelines that can be followed for selecting an
               appropriate data access technology are:
                  Use ADO.NETODBC a Java code native code
                       JDBC DB for writing a managed
                       (OLE) for for writing a Microsoft code
                       Microsoft writing for writing a targeting
                  based application, a VB 6 COMin Visual Basic,
                  SQL Server.
                  targeting the .NET Framework or C++.
                            Windows by using C application, or
                  C#, and C++.
                  a C++ application using COM.




    Ver. 1.0                      Session 1                        Slide 5 of 25
Developing Database Applications Using ADO.NET and XML
Understanding ADO.NET (Contd.)


                ADO.NET is a part of the .NET Framework architecture.




     Ver. 1.0                   Session 1                         Slide 6 of 25
Developing Database Applications Using ADO.NET and XML
The ADO.NET Object Model


               ADO.NET is based on an object model that is based on the
               standards laid down by W3C.
               The following figure shows the ADO.NET object model.




    Ver. 1.0                   Session 1                         Slide 7 of 25
Developing Database Applications Using ADO.NET and XML
The ADO.NET Object Model (Contd.)


                The two key components of ADO.NET Object model are:
                 Data provider               Is required for:
                 Dataset                         Connecting to a database.
                                                  Retrieving data.
                                                  Storing the data in a dataset.
                                                  Reading the retrieved data.
                                                  Updating the database.
                                              Has four key components:
                                                   Connection
                                                   Command
                                                   DataReader
                                                   DataAdapter




     Ver. 1.0                     Session 1                                  Slide 8 of 25
Developing Database Applications Using ADO.NET and XML
The ADO.NET Object Model (Contd.)


                The two key components of ADO.NET Object model are:
                 Data provider
                 Dataset                      Is a disconnected, cached set of
                                                records that are retrieved from a
                                                database.
                                               Is present in the Dataset class in
                                                the System.Data namespace.
                                               Has the following key
                                                components:
                                                    DataTableCollection
                                                    DataRelationCollection
                                                    DataTable
                                                    DataRowCollection
                                                    DataColoumnCollection



     Ver. 1.0                     Session 1                               Slide 9 of 25
Developing Database Applications Using ADO.NET and XML
Just a minute


                Which of the following components of a data provider is
                used to retrieve, insert, delete, or modify data in a data
                source?
                 1.   Connection
                 2.   Command
                 3.   DataReader
                 4.   DataAdapter




                Answer:
                 2. Command



     Ver. 1.0                       Session 1                          Slide 10 of 25
Developing Database Applications Using ADO.NET and XML
Features of ADO.NET


                The key features of ADO.NET are:
                   Disconnected data architecture   Applications connect to
                   Data cached in datasets          the database only while
                                                    The data is retrieved
                   Scalability                      retrieving anddatasets.
                                                    Database in updating
                                                    and storedoperations
                                                    data.can work withthe
                                                    Youperformed on the
                                                    are is the fundamental
                   Data transfer in XML format      XML
                                                    Connection withofaon
                                                    records insteadinthe
                                                    format stored
                                                    datasetfor data transfer
                                                    database is closed,
                                                    dataset as you work
                                                    the database.
                                                    in ADO.NET.
                                                    oncereal data. is
                                                    As a the data
                                                    with result,dataset is
                                                    Because a resources
                                                    retrieved. and the
                                                    Thesaved is
                                                    are dataset XML
                                                    stored in the
                                                    Connection candatathe
                                                    independentis meet
                                                    format, you of
                                                    database can
                                                    re-established when of
                                                    source anddemands the
                                                    transmit it you remain
                                                    increasing between
                                                    data needs to from the
                                                    disconnected be
                                                    users more efficiently.
                                                    different types of
                                                    updated.
                                                    data source.
                                                    applications.




     Ver. 1.0                     Session 1                          Slide 11 of 25
Developing Database Applications Using ADO.NET and XML
Creating and Managing Connections


                To create and manage connections, you need to:
                   Create a connection object.
                   Create a command object.
                   Open the connection object.
                   Execute the SQL statement in the command object.
                   Close the connection object.




     Ver. 1.0                    Session 1                            Slide 12 of 25
Developing Database Applications Using ADO.NET and XML
Creating a Connection Object


                Execute the following steps to create a connection to the
                database:
                 SqlConnection connection =    Create a SqlConnection object.
                 new SqlConnection();          SqlConnection class is used to
                                               connect to a SQL Server.
                 connection.ConnectionString = The ConnectionString property
                 "Data Source=SQLSERVER01;     Name of the Server to be used
                                               provides information, such as the
                                               when a connection is open
                 Initial Catalog=HR;           Name of the and database name,
                                               data source database
                                               that is used to establish a
                 User ID=sa;                   Used to specify the Server login
                                               connection with a database.
                                               account
                 Password=password";           Login password for the Server
                                                      account




     Ver. 1.0                     Session 1                           Slide 13 of 25
Developing Database Applications Using ADO.NET and XML
Just a minute


                Which of the following parameters of ConnectionString is
                used to specify the name of the database?
                 1.   Provider
                 2.   Initial Catalog
                 3.   Data source
                 4.   Database




                Answer:
                 2. Initial Catalog



     Ver. 1.0                           Session 1                  Slide 14 of 25
Developing Database Applications Using ADO.NET and XML
Creating a Command Object


               Execute the following steps to create a command object:
                SqlCommand cmd = new         To execute an SQL statement, you need
                                                 to
                SqlCommand
                                             create an instance of the SqlCommand
                (“SELECT * FROM              The two parameters that are passed to the
                                             class.
                monthlysalary“               SqlCommnad object are, the SQL query to
                ,connection);                be executed and the SqlConnection
                                             object.




    Ver. 1.0                    Session 1                                 Slide 15 of 25
Developing Database Applications Using ADO.NET and XML
Opening the Connection Object


                Execute the following steps to open a connection:


                //SqlConnection connection          It opens a database connection
                                                    with the property settings
                connection.Open();                  specified by the
                                                    ConnectionString property.




     Ver. 1.0                    Session 1                              Slide 16 of 25
Developing Database Applications Using ADO.NET and XML
Executing SQL Statements in the Command Object


                To execute the query passed in the Command object, you
                can call one of the following methods:
                    //Creating a SqlConnection object
                      SqlConnection connection = new
                      SqlConnection();
                    //Creates a connection string to the HR
                      database
                      connection.ConnectionString = "Data Source=
                      SQLSERVER01; Initial Catalog=HR; User
                      ID=sa; Password=niit#1234";
                      connection.Open();
                    //Creating a SqlCommand object
                      SqlCommand cmd = new SqlCommand("select *
                      from monthlysalary", connection);
                    //Creating SqlReader object
                      SqlDataReader myReader =
                      cmd.ExecuteReader();
     Ver. 1.0                   Session 1                        Slide 17 of 25
Developing Database Applications Using ADO.NET and XML
Closing the Connection Object


                Execute the following steps
                to close a connection:
                //SqlConnection connection    It closes the connection to the
                                              database.
                connection.Close();




     Ver. 1.0                    Session 1                             Slide 18 of 25
Developing Database Applications Using ADO.NET and XML
Closing the Connection Object (Contd.)


                Handling Connection Events:
                – The two key events for the SqlConnection class are:
                      StateChange event        This event occurs when the state
                      InfoMessage event         of the connection changes.
                                               This event occurs when an
                                               It receives an message or type
                                                informational argument of
                                                StateChangeEventArgs.
                                                warning is returned from a data
                                               source.
                                                StateChangeEventArgs has the
                                               following properties:
                                                It receives an argument of type
                                                    CurrentState
                                                SqlInfoMessageEventArgs.
                                                    OriginalState
                                               SqlInfoMessageEventArgs
                                                has the following properties:
                                                    Errors
                                                    Message
                                                    Source




     Ver. 1.0                     Session 1                             Slide 19 of 25
Developing Database Applications Using ADO.NET and XML
Implementing Connection Pooling


                Connection pooling enables a data source to reuse
                connections for a particular user.
                Connection pooling is controlled by certain parameters that
                are placed into the connection string.
                    • Connection timeout       It is the time in seconds to wait
                    • Min pool size            while a connection tothe data
                                               It is used to mention the
                                               source is attempted. The
                                               minimum to mention the
                    • Max pool size            It is used number of
                                               default valuemaintained in the
                                               connections is 15 of seconds.
                    •                          maximum number the
                                               When true, it causes
                      Pooling                  pool. The default value the pool.
                                               connections allowed in is 0. to
                                               request for a new connection
                    • Connection reset        It indicates that the database
                                               The default value is 100.
                                               be drawn from the pool.
                    •                          connection the maximum time
                                               It specifies will be reset when
                      Load balancing
                                               the connection is removed from
                                               in seconds that a pooled
                      timeout, connection
                                               the pool. should live.
                                               connection
                      lifetime
                    • Enlist                  When the value is true, the
                                               connection is automatically enlisted
                                               into the creation thread’s current
                                               transaction context.
     Ver. 1.0                    Session 1                                Slide 20 of 25
Developing Database Applications Using ADO.NET and XML
Implementing Connection Pooling (Contd.)



                                            A request for a connection is
                                             made by the application using
                                             the Open() method.
                                            If the Pooling property is set
                                             to true, the pooler attempts to
                                             acquire a connection from the
                                             pool otherwise a new
                                             connection is created.
                                            Close the connection by
                                             calling the close() method.




     Ver. 1.0              Session 1                              Slide 21 of 25
Developing Database Applications Using ADO.NET and XML
Demo: Retrieving Data from a SQL Database


                Problem Statement:
                   Tebisco is a leading producer and distributor of snacks in the
                   United States. It is planning to start its annual appraisal
                   process. Before starting up with the appraisal process, the
                   senior management requires a list of all employees. The details
                   include employee name, employee code, current position,
                   designation, and joining date.
                   As a member of the development team, you have been asked
                   to develop an application that will display the employee details.

                   Hint: You need to refer to the Employee table of the HR
                   database.




     Ver. 1.0                      Session 1                               Slide 22 of 25
Developing Database Applications Using ADO.NET and XML
Summary


               In this session, you learned that:
                  ADO.NET is a data access programming model for accessing
                  the data stored in a database from a .NET application.
                  The ADO.NET object model consists of two main components,
                  data provider and dataset.
                  A data provider is used for connecting to a database, retrieving
                  data, storing the data in a dataset, reading the retrieved data,
                  and updating the database.
                  The various types of data providers are:
                      .NET Framework data provider for SQL Server
                      .NET Framework data provider for OLEDB
                      .NET Framework data provider for ODBC
                      .NET Framework data provider for Oracle




    Ver. 1.0                      Session 1                              Slide 23 of 25
Developing Database Applications Using ADO.NET and XML
Summary (Contd.)


               The four key components of a data provider are:
                   Connection
                   Commnd
                   DataReader
                   DataAdapter
               The dataset is memory-based relational representation of data.
               The main features of ADO.NET are:
                    Disconnected data architecture
                    Data cached in datasets
                    Scalability
                    Data transfer in XML format




    Ver. 1.0                      Session 1                          Slide 24 of 25
Developing Database Applications Using ADO.NET and XML
Summary (Contd.)


                 In order to create and manage connection to the database, you
                 need to perform the following steps:
                   1. Create a connection object.
                   2. Create a command object.
                   3. Open the connection object.
                   4. Execute the SQL statement in the command object.
                   5. Close the connection object.
                The two key events for the SqlConnection class are:
                    StateChange event
                    InfoMessage event
                Connection pooling enables a data source to reuse
                 connections for a particular user.




    Ver. 1.0                      Session 1                              Slide 25 of 25

Más contenido relacionado

La actualidad más candente

Dealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETDealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETFernando G. Guerrero
 
Ado.net & data persistence frameworks
Ado.net & data persistence frameworksAdo.net & data persistence frameworks
Ado.net & data persistence frameworksLuis Goldster
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to adoHarman Bajwa
 
ADO.NET difference faqs compiled- 1
ADO.NET difference  faqs compiled- 1ADO.NET difference  faqs compiled- 1
ADO.NET difference faqs compiled- 1Umar Ali
 
Database programming in vb net
Database programming in vb netDatabase programming in vb net
Database programming in vb netZishan yousaf
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETEverywhere
 
Intake 38 data access 1
Intake 38 data access 1Intake 38 data access 1
Intake 38 data access 1Mahmoud Ouf
 
PATTERNS07 - Data Representation in C#
PATTERNS07 - Data Representation in C#PATTERNS07 - Data Representation in C#
PATTERNS07 - Data Representation in C#Michael Heron
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastoreHaris Khan
 

La actualidad más candente (20)

Dealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETDealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NET
 
Ado.net & data persistence frameworks
Ado.net & data persistence frameworksAdo.net & data persistence frameworks
Ado.net & data persistence frameworks
 
Ado.net
Ado.netAdo.net
Ado.net
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
ADO.NET difference faqs compiled- 1
ADO.NET difference  faqs compiled- 1ADO.NET difference  faqs compiled- 1
ADO.NET difference faqs compiled- 1
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Ado.net
Ado.netAdo.net
Ado.net
 
Database programming in vb net
Database programming in vb netDatabase programming in vb net
Database programming in vb net
 
Introduction to ado.net
Introduction to ado.netIntroduction to ado.net
Introduction to ado.net
 
Intake 38 10
Intake 38 10Intake 38 10
Intake 38 10
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NET
 
Unit4
Unit4Unit4
Unit4
 
Intake 38 data access 1
Intake 38 data access 1Intake 38 data access 1
Intake 38 data access 1
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 
PATTERNS07 - Data Representation in C#
PATTERNS07 - Data Representation in C#PATTERNS07 - Data Representation in C#
PATTERNS07 - Data Representation in C#
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastore
 
6 database
6 database 6 database
6 database
 

Similar a Ado.net session01

Vb net xp_05
Vb net xp_05Vb net xp_05
Vb net xp_05Niit Care
 
ADO .NET by Sonu Vishwakarma
ADO .NET by Sonu VishwakarmaADO .NET by Sonu Vishwakarma
ADO .NET by Sonu VishwakarmaSonu Vishwakarma
 
Vb.net session 16
Vb.net session 16Vb.net session 16
Vb.net session 16Niit Care
 
Vb.net session 06
Vb.net session 06Vb.net session 06
Vb.net session 06Niit Care
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkAkhil Mittal
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity FrameworkMahmoud Tolba
 
Dao pattern
Dao patternDao pattern
Dao patternciriako
 
Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010David McCarter
 
1 introduction
1   introduction1   introduction
1 introductionNgeam Soly
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity FrameworkHasnain Iqbal
 
DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1YOGESH SINGH
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentalsMadhuri Kavade
 
Jdbc Lecture5
Jdbc Lecture5Jdbc Lecture5
Jdbc Lecture5phanleson
 

Similar a Ado.net session01 (20)

Vb net xp_05
Vb net xp_05Vb net xp_05
Vb net xp_05
 
ADO .NET by Sonu Vishwakarma
ADO .NET by Sonu VishwakarmaADO .NET by Sonu Vishwakarma
ADO .NET by Sonu Vishwakarma
 
Ado
AdoAdo
Ado
 
Entity Framework
Entity FrameworkEntity Framework
Entity Framework
 
Vb.net session 16
Vb.net session 16Vb.net session 16
Vb.net session 16
 
Vb.net session 06
Vb.net session 06Vb.net session 06
Vb.net session 06
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFramework
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Entity framework1
Entity framework1Entity framework1
Entity framework1
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
 
Dao pattern
Dao patternDao pattern
Dao pattern
 
Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010
 
1 introduction
1   introduction1   introduction
1 introduction
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
 
DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1DEE 431 Introduction to DBMS Slide 1
DEE 431 Introduction to DBMS Slide 1
 
unit 3.docx
unit 3.docxunit 3.docx
unit 3.docx
 
Microsoft data access components
Microsoft data access componentsMicrosoft data access components
Microsoft data access components
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentals
 
Jdbc Lecture5
Jdbc Lecture5Jdbc Lecture5
Jdbc Lecture5
 
Day4
Day4Day4
Day4
 

Más de Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Último

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Último (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Ado.net session01

  • 1. Developing Database Applications Using ADO.NET and XML Rationale Business applications need to manage voluminous data. Data is generally stored in a relational database in the form of related tables or is stored in text format in XML documents. Most business applications allow users to retrieve the data stored in a database and present it in a user-friendly interface without writing the database commands. ADO.NET is a model used by .NET applications to communicate with a database for retrieving, accessing, and updating data. This module will provide the necessary skills to the students to work as a database application developer in the industry. Ver. 1.0 Session 1 Slide 1 of 25
  • 2. Developing Database Applications Using ADO.NET and XML Prerequisites A student registering for this module should be able to perform the following tasks: Work with XML Work with SQL queries Ver. 1.0 Session 1 Slide 2 of 25
  • 3. Developing Database Applications Using ADO.NET and XML Case Study - Tebisco Brief History Tebisco is a leading producer and distributor of snacks in the U.S., as well as in most of the company’s 23 international markets. In 1998, consumers spent $9.2 billion on Tebisco’s snacks, $1.4 billion more than in the previous year. Tebisco started as a small bakery in Round Rock, Texas in 1978. In a short time, its gingersnaps, macaroons, shortbread and other cookies were popular all over the U.S. Three years ago, the management embarked on a rapid expansion plan. They set up offices in Asia and Europe, in addition to strengthening their U.S. operations. Tebisco has got a centralized database management system whereby the information about all the HR activities is maintained. Ver. 1.0 Session 1 Slide 3 of 25
  • 4. Developing Database Applications Using ADO.NET and XML Objectives In this session, you will learn to: Understand the ADO.NET object model Create and manage connections Ver. 1.0 Session 1 Slide 4 of 25
  • 5. Developing Database Applications Using ADO.NET and XML Understanding ADO.NET Business applications allow users to retrieve data from a database by presenting data in a user-friendly interface. User need not remember the database commands for retrieving or updating data in the database. Microsoft has created a family of data access technologies to help programmers build efficient applications to access data, regardless of its source. The guidelines that can be followed for selecting an appropriate data access technology are: Use ADO.NETODBC a Java code native code JDBC DB for writing a managed (OLE) for for writing a Microsoft code Microsoft writing for writing a targeting based application, a VB 6 COMin Visual Basic, SQL Server. targeting the .NET Framework or C++. Windows by using C application, or C#, and C++. a C++ application using COM. Ver. 1.0 Session 1 Slide 5 of 25
  • 6. Developing Database Applications Using ADO.NET and XML Understanding ADO.NET (Contd.) ADO.NET is a part of the .NET Framework architecture. Ver. 1.0 Session 1 Slide 6 of 25
  • 7. Developing Database Applications Using ADO.NET and XML The ADO.NET Object Model ADO.NET is based on an object model that is based on the standards laid down by W3C. The following figure shows the ADO.NET object model. Ver. 1.0 Session 1 Slide 7 of 25
  • 8. Developing Database Applications Using ADO.NET and XML The ADO.NET Object Model (Contd.) The two key components of ADO.NET Object model are:  Data provider Is required for:  Dataset  Connecting to a database.  Retrieving data.  Storing the data in a dataset.  Reading the retrieved data.  Updating the database. Has four key components: Connection Command DataReader DataAdapter Ver. 1.0 Session 1 Slide 8 of 25
  • 9. Developing Database Applications Using ADO.NET and XML The ADO.NET Object Model (Contd.) The two key components of ADO.NET Object model are:  Data provider  Dataset  Is a disconnected, cached set of records that are retrieved from a database.  Is present in the Dataset class in the System.Data namespace.  Has the following key components:  DataTableCollection  DataRelationCollection  DataTable  DataRowCollection  DataColoumnCollection Ver. 1.0 Session 1 Slide 9 of 25
  • 10. Developing Database Applications Using ADO.NET and XML Just a minute Which of the following components of a data provider is used to retrieve, insert, delete, or modify data in a data source? 1. Connection 2. Command 3. DataReader 4. DataAdapter Answer: 2. Command Ver. 1.0 Session 1 Slide 10 of 25
  • 11. Developing Database Applications Using ADO.NET and XML Features of ADO.NET The key features of ADO.NET are: Disconnected data architecture Applications connect to Data cached in datasets the database only while The data is retrieved Scalability retrieving anddatasets. Database in updating and storedoperations data.can work withthe Youperformed on the are is the fundamental Data transfer in XML format XML Connection withofaon records insteadinthe format stored datasetfor data transfer database is closed, dataset as you work the database. in ADO.NET. oncereal data. is As a the data with result,dataset is Because a resources retrieved. and the Thesaved is are dataset XML stored in the Connection candatathe independentis meet format, you of database can re-established when of source anddemands the transmit it you remain increasing between data needs to from the disconnected be users more efficiently. different types of updated. data source. applications. Ver. 1.0 Session 1 Slide 11 of 25
  • 12. Developing Database Applications Using ADO.NET and XML Creating and Managing Connections To create and manage connections, you need to: Create a connection object. Create a command object. Open the connection object. Execute the SQL statement in the command object. Close the connection object. Ver. 1.0 Session 1 Slide 12 of 25
  • 13. Developing Database Applications Using ADO.NET and XML Creating a Connection Object Execute the following steps to create a connection to the database: SqlConnection connection = Create a SqlConnection object. new SqlConnection(); SqlConnection class is used to connect to a SQL Server. connection.ConnectionString = The ConnectionString property "Data Source=SQLSERVER01; Name of the Server to be used provides information, such as the when a connection is open Initial Catalog=HR; Name of the and database name, data source database that is used to establish a User ID=sa; Used to specify the Server login connection with a database. account Password=password"; Login password for the Server account Ver. 1.0 Session 1 Slide 13 of 25
  • 14. Developing Database Applications Using ADO.NET and XML Just a minute Which of the following parameters of ConnectionString is used to specify the name of the database? 1. Provider 2. Initial Catalog 3. Data source 4. Database Answer: 2. Initial Catalog Ver. 1.0 Session 1 Slide 14 of 25
  • 15. Developing Database Applications Using ADO.NET and XML Creating a Command Object Execute the following steps to create a command object: SqlCommand cmd = new To execute an SQL statement, you need to SqlCommand create an instance of the SqlCommand (“SELECT * FROM The two parameters that are passed to the class. monthlysalary“ SqlCommnad object are, the SQL query to ,connection); be executed and the SqlConnection object. Ver. 1.0 Session 1 Slide 15 of 25
  • 16. Developing Database Applications Using ADO.NET and XML Opening the Connection Object Execute the following steps to open a connection: //SqlConnection connection It opens a database connection with the property settings connection.Open(); specified by the ConnectionString property. Ver. 1.0 Session 1 Slide 16 of 25
  • 17. Developing Database Applications Using ADO.NET and XML Executing SQL Statements in the Command Object To execute the query passed in the Command object, you can call one of the following methods: //Creating a SqlConnection object SqlConnection connection = new SqlConnection(); //Creates a connection string to the HR database connection.ConnectionString = "Data Source= SQLSERVER01; Initial Catalog=HR; User ID=sa; Password=niit#1234"; connection.Open(); //Creating a SqlCommand object SqlCommand cmd = new SqlCommand("select * from monthlysalary", connection); //Creating SqlReader object SqlDataReader myReader = cmd.ExecuteReader(); Ver. 1.0 Session 1 Slide 17 of 25
  • 18. Developing Database Applications Using ADO.NET and XML Closing the Connection Object Execute the following steps to close a connection: //SqlConnection connection It closes the connection to the database. connection.Close(); Ver. 1.0 Session 1 Slide 18 of 25
  • 19. Developing Database Applications Using ADO.NET and XML Closing the Connection Object (Contd.) Handling Connection Events: – The two key events for the SqlConnection class are: StateChange event  This event occurs when the state InfoMessage event of the connection changes.  This event occurs when an  It receives an message or type informational argument of StateChangeEventArgs. warning is returned from a data  source. StateChangeEventArgs has the  following properties: It receives an argument of type  CurrentState SqlInfoMessageEventArgs.  OriginalState  SqlInfoMessageEventArgs has the following properties: Errors Message Source Ver. 1.0 Session 1 Slide 19 of 25
  • 20. Developing Database Applications Using ADO.NET and XML Implementing Connection Pooling Connection pooling enables a data source to reuse connections for a particular user. Connection pooling is controlled by certain parameters that are placed into the connection string. • Connection timeout It is the time in seconds to wait • Min pool size while a connection tothe data It is used to mention the source is attempted. The minimum to mention the • Max pool size It is used number of default valuemaintained in the connections is 15 of seconds. • maximum number the When true, it causes Pooling pool. The default value the pool. connections allowed in is 0. to request for a new connection • Connection reset  It indicates that the database The default value is 100. be drawn from the pool. • connection the maximum time It specifies will be reset when Load balancing the connection is removed from in seconds that a pooled timeout, connection the pool. should live. connection lifetime • Enlist  When the value is true, the connection is automatically enlisted into the creation thread’s current transaction context. Ver. 1.0 Session 1 Slide 20 of 25
  • 21. Developing Database Applications Using ADO.NET and XML Implementing Connection Pooling (Contd.)  A request for a connection is made by the application using the Open() method.  If the Pooling property is set to true, the pooler attempts to acquire a connection from the pool otherwise a new connection is created.  Close the connection by calling the close() method. Ver. 1.0 Session 1 Slide 21 of 25
  • 22. Developing Database Applications Using ADO.NET and XML Demo: Retrieving Data from a SQL Database Problem Statement: Tebisco is a leading producer and distributor of snacks in the United States. It is planning to start its annual appraisal process. Before starting up with the appraisal process, the senior management requires a list of all employees. The details include employee name, employee code, current position, designation, and joining date. As a member of the development team, you have been asked to develop an application that will display the employee details. Hint: You need to refer to the Employee table of the HR database. Ver. 1.0 Session 1 Slide 22 of 25
  • 23. Developing Database Applications Using ADO.NET and XML Summary In this session, you learned that: ADO.NET is a data access programming model for accessing the data stored in a database from a .NET application. The ADO.NET object model consists of two main components, data provider and dataset. A data provider is used for connecting to a database, retrieving data, storing the data in a dataset, reading the retrieved data, and updating the database. The various types of data providers are: .NET Framework data provider for SQL Server .NET Framework data provider for OLEDB .NET Framework data provider for ODBC .NET Framework data provider for Oracle Ver. 1.0 Session 1 Slide 23 of 25
  • 24. Developing Database Applications Using ADO.NET and XML Summary (Contd.) The four key components of a data provider are:  Connection  Commnd  DataReader  DataAdapter The dataset is memory-based relational representation of data. The main features of ADO.NET are: Disconnected data architecture Data cached in datasets Scalability Data transfer in XML format Ver. 1.0 Session 1 Slide 24 of 25
  • 25. Developing Database Applications Using ADO.NET and XML Summary (Contd.) In order to create and manage connection to the database, you need to perform the following steps: 1. Create a connection object. 2. Create a command object. 3. Open the connection object. 4. Execute the SQL statement in the command object. 5. Close the connection object.  The two key events for the SqlConnection class are:  StateChange event  InfoMessage event  Connection pooling enables a data source to reuse connections for a particular user. Ver. 1.0 Session 1 Slide 25 of 25