1 / 66

Data Access in .NET Applications

Data Access in .NET Applications. Tarmo Tali System Engineer Microsoft Baltic. Agenda. Part I ADO.NET Overview Visual Studio .NET Tools XML Designer Part II Difference between ADO and ADO.NET Programming with ADO.NET XML Support Advanced Features Converting ADO to ADO.NET

Télécharger la présentation

Data Access in .NET Applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Access in .NET Applications Tarmo Tali System Engineer Microsoft Baltic

  2. Agenda • Part I • ADO.NET Overview • Visual Studio .NET Tools • XML Designer • Part II • Difference between ADO and ADO.NET • Programming with ADO.NET • XML Support • Advanced Features • Converting ADO to ADO.NET • When To Use What?

  3. Session Prerequisites • Relational Database Design and Programming • Visual Basic 6.0 / C++ Programming • Microsoft ADO • Understanding of XML

  4. Important announcement!!! • Visual Studio.NETis released!!!

  5. Agenda • Part I • ADO.NET Overview • Visual Studio .NET Tools • XML Designer • Part II • Difference between ADO and ADO.NET • Programming with ADO.NET • XML Support • Advanced Features • Converting ADO to ADO.NET • When To Use What?

  6. ADO.NETBackground • Evolve ADO to multi-tier architecture • Interoperability • Based on standards like XML, XSD • Scalability • Targets distributed, disconnected web scenarios • Productivity • Common programming model over heterogeneous data

  7. ADO.NETDesign Philosophy • Factored components • Explicit model; No black boxes! • Customers/helper code wires together components • Predictable behavior, semantics • Optimized performance • Disconnected Relational DataSet • Unified Data Story (data, xml, cache objects) • Data is Data; object model is choice • XML objects feel like XML, Data objects feels like Data, Typed Objects feel like objects • Integrated into the Framework

  8. ADO.NETADO.NET Architecture Presentation Tier Windows Forms MyApp.exe Data Set Data Tier Business Tier Web Forms InternetIntranet IE Data Object (Class) SqlDataAdapter d Data Set XML Data Set SqlDataAdapter d Business to Business (BizTalk, for example)

  9. ADO.NETKey Concepts • Native Support For XML • Focuses on Most Frequent • Streaming data • Large result sets • Maximum throughput and performance • Client side static data • In-memory relational view • Separation of data, view, and database implementation specifics • Minimize Possibility For Mistakes • Server-side static cursors • Forget to MoveNext

  10. ADO.NET Versus ADO • Explicit Model for Updates • XML: built-in serialization and relational mapping • Relational object model • ForEach rather than MoveNext • Extend schema at runtime

  11. Controls,Designers,Code-gen, etc XSL/T, X-Path,Validation, etc XmlData-Document DataSet Sync XmlReader XmlText- Reader XmlNode- Reader ADO.NET object model DataAdapter DataReader Command Connection Managed Provider

  12. ADO.NETDataSet DataSet Tables Table • In memory store for client,middle-tier data • Relational view of data • XML to the core • Loads/saves data as XML • Loads/saves relational schema as XSD • Disconnected, remotable object • No knowledge of data source Columns Column Constraints Constraint Rows Row Relations Relation

  13. ADO.NETTyped DataSet • Class generated by the designer • Inherits from DataSet • Schema coded into the class • Concise, readable code • Compile time type checking ds.Tables(“Customers”).Rows(0).Columns(“Name”) = _ “Steve Ballmer” ds.Customers(0).Name = “Steve Ballmer”

  14. DataSetCommand Connection SelectCommand UpdateCommand InsertCommand DeleteCommand TableMappings ADO.NETDataAdapter • Manages exchange between DataSet and data source • ADO-like connections andcommands • Interacts with DataSet to provide disconnected functionality • Managed Provider SDK

  15. Agenda • Part I • ADO.NET Overview • Visual Studio .NET Tools • XML Designer • Part II • Difference between ADO and ADO.NET • Programming with ADO.NET • XML Support • Advanced Features • Converting ADO to ADO.NET • When To Use What?

  16. Visual Studio .NET Tools • Component Designer • XML Designer • Schema Designer • Web Services/Web References

  17. Visual Studio .NET ToolsComponent Designer • DataAdapter Wizard • Auto-generate Update/Delete/Insert statements • Auto-config parameters collection for SQL statements and stored procedures • Generate Typed Datasets • Table Mappings Dialog • Map database tables/columns to new or existing Typed DataSets

  18. SQL Server Customers Web Service DataSet DataSetCommand DataSetCommand XML Access Orders Demo 1: Return Data from a Web Service IIS

  19. Visual Studio .NET ToolsWeb Services / Web References • Web Services • Stream DataSets over the wire as XML • Publish schemas to client applications • Web References • Discover and consume methods, schemas • Program against Web Services as objects

  20. Windows Form DataSet DataSet XML Web Service GetCustomers Demo 2: Windows Form vs Web Service

  21. Agenda • Part I • ADO.NET Overview • Visual Studio .NET Tools • XML Designer • Part II • Difference between ADO and ADO.NET • Programming with ADO.NET • XML Support • Advanced Features • Converting ADO to ADO.NET • When To Use What?

  22. XML DesignerXML Documents and Schemas • XML Documents/Data • XSD Schemas • W3C recommended XML schema language • Replaces DTDs • Describes shape/structure of XML data • Validation of XML data • Contracts for data exchange • Map to relational schemas

  23. XML DesignerXML Documents and Schemas • Visually design XML Data and XSD Schemas • Rich XML source editing • Drag/drop creation of schemas from database • Infer schemas from XML data • Generate typed DataSets

  24. Demo 3: XML Designer • XSD schema -> XML data • XML data -> XSD schema

  25. Part I - Summary • Data = XML = Data • ADO.NET = distributed, disconnected, scalable, XML-based data architecture • Visual Studio .NET = RAD for multi-tier data apps

  26. Agenda • Part I • ADO.NET Overview • Visual Studio .NET Tools • XML Designer • Part II • Difference between ADO and ADO.NET • Programming with ADO.NET • XML Support • Advanced Features • Converting ADO to ADO.NET • When To Use What?

  27. Introduction to ADO.NETComparison Between ADO and ADO.NET

  28. Introduction to ADO.NETComparison Between ADO and ADO.NET

  29. Agenda • Part I • ADO.NET Overview • Visual Studio .NET Tools • XML Designer • Part II • Difference between ADO and ADO.NET • Programming with ADO.NET • XML Support • Advanced Features • Converting ADO to ADO.NET • When To Use What?

  30. Controls,Designers,Code-gen, etc XSL/T, X-Path,Validation, etc XmlData-Document DataSet Sync XmlReader XmlText- Reader XmlNode- Reader ADO.NET object model DataAdapter DataReader Command Connection Managed Provider

  31. Programming with ADO.NETManaged Providers • Manages Interaction To A Data Source • Managed equivalent of OLE DB layer • Directly exposes consumer interfaces • Not a full featured data store interface • Specific to (Optimized for) DataSource • Managed Provider Object Model • Connection • Command • DataReader

  32. Programming with ADO.NETConnection • Represents A Connection To The Data Source • On A Connection, You Can… • Customize the connection to the database • Begin, commit, and abort transactions • Equivalent To The ADODB.Connection Object

  33. Programming with ADO.NET Command Object • Represents A Command To Be Executed • Not necessarily SQL • With An ADO Command You Can: • Define a statement to be executed on the server • Set parameter information for that command • Retrieve return values from command execution • Corresponds To ADODB.Command Object • May Contain Parameters • Values to be used when executing a statement

  34. Programming with ADO.NET Command Object • ExecuteNonQuery • ExecuteReader • ExecuteScalar • ExecuteXmlReader (for SqlCommand object only)

  35. Programming with ADO.NETDataSet • In Memory Store For Client Data • Relational View Of Data • Tables, Columns, Rows, Constraints, Relations • Persist Data And Schema As XML • Explicit Disconnected Model • Disconnected, remotable object • Array-like indexing • No Knowledge Of Data Source Or Properties • Common model over heterogeneous data • Predictable performance characteristics

  36. DataRow DataColumn DataTable Programming with ADO.NETDataSet DataTable DataSet Relations Constraints XML Schema

  37. Programming with ADO.NETTyped DataSet • Class Generated At Design Time • Inherits from DataSet • Schema coded into the class • Benefits • Statement completion • Compile time type checking • Concise, readable code

  38. Programming with ADO.NETDataAdapter • Manages Data Exchange BetweenDataSet And Data Source • Fill(DataSet or DataTable) • Update(DataSet or DataTable) • Provides Mappings Between Tables & Columns • User Can Override Insert/Update/Delete Commands • Autogen component available • Allows Single DataSet To Be Populated FromMultiple Different Datasources

  39. SelectCommand InsertCommand UpdateCommand DeleteCommand Programming with ADO.NETDataAdapter Database DataAdapter DataSet TableMappings

  40. Programming with ADO.NETDataBinding • DataView • Thinks of this as a view on the DataTable • Allows setting Sort Order and Filter on a view of the table • Any number of DataViews can be created on a table to enable different views of the same table • Used for databinding • DataSetView • Think of this as a view on top of the DataSet • Allows setting sort orders and filters • Allows “linking” of DataViews • Used for databinding

  41. Programming with ADO.NETSources for DataBinding • DataReader • DataTable • DataView • DataSet • DataSetView • Array • Collection • IList

  42. Programming with ADO.NETDataReader • Fast, Forward-Only, Read-Only Access To Data • Works Like A Socket • Allows Strongly-Typed Access • Must be closed

  43. Demo 4: Using ADO.NET • DataSet, DataAdapter and DataReader

  44. Agenda • Part I • ADO.NET Overview • Visual Studio .NET Tools • XML Designer • Part II • Difference between ADO and ADO.NET • Programming with ADO.NET • XML Support • Advanced Features • Converting ADO to ADO.NET • When To Use What?

  45. XML SupportADO.NET and XML • DataSet • Loads/saves XML data into/out of DataSet • Schema can be loaded/saved as XSD • Schema can be inferred from XML Data • XmlDataDocument • Exposes relational view over structured XML • Allows strong typing, control binding, relational access of XML data • Allows XML tools (schema validation, XSL/T, XPath queries) against relational data • Preserves full fidelity of XML Document

  46. XML SupportXML View Of Relational Data • XmlDataDocument • View/edit relational subset of XML document within full XmlDocument • DataDocumentNavigator • X/Path queries • XSL Transformations • Validation • SQL XML • Xml streamed from SQLServer • Support for UpdateGrams

  47. XML SupportADO.NET and XML • DataSet Provides Direct Handling Of XML Documents and Schemas • ReadXml() • ReadXmlSchema() • WriteXml() • WriteXmlSchema()

  48. Demo 5: XML Support • Read and Write XML Files

  49. Agenda • Part I • ADO.NET Overview • Visual Studio .NET Tools • XML Designer • Part II • Difference between ADO and ADO.NET • Programming with ADO.NET • XML Support • Advanced Features • Converting ADO to ADO.NET • When To Use What?

More Related