Docstoc

ADO.NET

Document Sample
ADO.NET Powered By Docstoc
					 Introduction to ADO.NET


         Jenny Chang
Student Ambassador to Microsoft
       CSU – Los Angeles
                 Agenda
– Introduce you to ADO.NET
– Describe the connected layer of ADO.NET as
  implemented by .NET data providers
– Describe the disconnected layer of ADO.NET as
  implemented by the DataSet
– Demonstrate integration of ADO.NET within Visual
  Studio
               Why ADO.NET?
• ADO works great, but
  – Requires COM and Windows®
  – Recordsets don’t travel well across the Internet
  – Connected behavior is hard to work with
• ADO.NET solves these problems
  – Uses XML under the covers for all data transport
  – XML has no runtime/transport requirements
     • No special code required to marshal across the
       Internet
• ADO.NET requires new mindset
  – All data access disconnected
  – All data transport uses XML
              What Is ADO .NET?
• ADO.NET is a collection of classes, interfaces,
  structures, and enumerated types that manage
  data access from relational data stores within the
  .NET Framework
   – These collections are organized into namespaces:
      • System.Data, System.Data.OleDb,
        System.Data.SqlClient, etc.
• ADO.NET is an evolution from ADO.
   – Does not share the same object model, but shares
     many of the same paradigms and functionality!
     Connected Or Disconnected?
• System.Data namespace contains disconnected
  set of objects
  – DataSet, DataTable, DataRow, and so on
• Specific namespaces (System.Data.OleDb and
  System.Data.SqlClient) contain connected
  objects
  – SqlDataAdapter/OleDbDataAdapter
  – SqlConnection/OleDbConnection
  – SqlDataReader/OleDbDataReader
Connected Or Disconnected?
   With ADO, a fundamental question is:
    Where is the data managed?
      On the client?
      On the server?
      A mixture of the two?
 The answer in ADO
 …it depends on the cursor you are using.
 With ADO.NET:
      Data is always on the client (via DataSet) or
      on its way to the client (via IDataReader)
                   ADO.NET Architecture
 Presentation Tier
Windows Forms
 MyApp.Exe

               DataSet


                                     Business Tier                        Data Tier
                          Internet
Web Forms                 Intranet   Data Object (Class)
 IE
                                                           Data Adapter
                                            DataSet
                         XML
               DataSet
                                                           Data Adapter




 Business to Business



(BizTalk, for example)
ADO.NET
              .NET Data Provider




                                            ODBC Driver
                                   ODBC
                                                                ODBC
                 Connection
                                                               RDBMS




                                            OLE DB Provider
Application




                  Command

                                   OLE DB
                                                               OLE DB
                                                               RDBMS

                 Data Reader



                                                              SQL Server
                Data Adapter
             ADO.NET Objects
• Connection
  – Connects to data source
• Command
  – Executes SELECT, INSERT, UPDATE and DELETE
    commands
• Data Reader
  – Forward-only, read-only stream of data
• Data Adapter
  – Connects a DataSet to a data source
           Working With Data
• If you need full data access, use DataAdapter
  object (SQLDataAdapter, OleDbDataAdapter)
• DataAdapter represents a set of data
  commands and a database connection
  – Fills a DataSet (using Fill method)
  – Updates data (using Update method)
            Working With Data
• Use Fill method to fill the DataSet
  – DataSet provides local cache for disconnected
    data
  – All data marshaled as XML
• Make changes in cached data
• Use Update method to write changes from
  cached data back to data source
       Getting Data Into A DataSet
• DataAdapter has four Command properties
   – SelectCommand/DeleteCommand
   – InsertCommand/UpdateCommand
   – Each property contains a Command object
• DataAdapter uses these Command objects for
  selecting, updating, and so on
   – Call the Update method to change data
• Call the Fill method to execute the SelectCommand
   – Fills a DataSet
DataSet Object
   Relational views of data        DataSet
                                       Tables
       Contains tables, columns,             Table
        rows, constraints,                      Columns

        views, and relations                          Column
                                                Constraints
   Disconnected model                                Constraint

       Has no knowledge                        Rows

        of data source                                Row
                                       Relations
       Array-like indexing                   Relation

       Strong typing
       Supports data binding
DEMO: Setting Up Connections
   in Visual Studio.NET
                  Summary
• ADO.NET provides a rich API for working
  with data
• ADO.NET has been designed to support
  legacy architectures as well as Internet-
  enabled, n-tier designs
• The .NET Framework’s extensive XML
  support means greater reach for all of your
  data-enabled applications
                   References
• Using ADO.NET (VB.NET)
  http://msdn.microsoft.com/library/en-
  us/Dndotnet/html/Usingadonet.asp?frame=true
• ADO.NET Quick Tutorials (C#, VB.NET, JScript)
  http://samples.gotdotnet.com/quickstart/howto/default
  .aspx?url=/quickstart/howto/doc/adoplus/adoplusovervi
  ew.aspx
• Download Tech Talks Slides & Handouts
  http://jenny.sybay.com/dotnet
        Questions?

Don’t Forget to Fill Out the
     Evaluation Form
            &
    Win Some Prizes!

				
DOCUMENT INFO
Shared By:
Tags: ADO.NET
Stats:
views:15
posted:12/12/2011
language:English
pages:18