660 likes | 894 Views
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
E N D
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 • When To Use What?
Session Prerequisites • Relational Database Design and Programming • Visual Basic 6.0 / C++ Programming • Microsoft ADO • Understanding of XML
Important announcement!!! • Visual Studio.NETis released!!!
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?
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
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
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)
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
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
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
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
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”
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
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?
Visual Studio .NET Tools • Component Designer • XML Designer • Schema Designer • Web Services/Web References
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
SQL Server Customers Web Service DataSet DataSetCommand DataSetCommand XML Access Orders Demo 1: Return Data from a Web Service IIS
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
Windows Form DataSet DataSet XML Web Service GetCustomers Demo 2: Windows Form vs Web Service
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?
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
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
Demo 3: XML Designer • XSD schema -> XML data • XML data -> XSD schema
Part I - Summary • Data = XML = Data • ADO.NET = distributed, disconnected, scalable, XML-based data architecture • Visual Studio .NET = RAD for multi-tier data apps
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?
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?
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
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
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
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
Programming with ADO.NET Command Object • ExecuteNonQuery • ExecuteReader • ExecuteScalar • ExecuteXmlReader (for SqlCommand object only)
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
DataRow DataColumn DataTable Programming with ADO.NETDataSet DataTable DataSet Relations Constraints XML Schema
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
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
SelectCommand InsertCommand UpdateCommand DeleteCommand Programming with ADO.NETDataAdapter Database DataAdapter DataSet TableMappings
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
Programming with ADO.NETSources for DataBinding • DataReader • DataTable • DataView • DataSet • DataSetView • Array • Collection • IList
Programming with ADO.NETDataReader • Fast, Forward-Only, Read-Only Access To Data • Works Like A Socket • Allows Strongly-Typed Access • Must be closed
Demo 4: Using ADO.NET • DataSet, DataAdapter and DataReader
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?
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
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
XML SupportADO.NET and XML • DataSet Provides Direct Handling Of XML Documents and Schemas • ReadXml() • ReadXmlSchema() • WriteXml() • WriteXmlSchema()
Demo 5: XML Support • Read and Write XML Files
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?