Data Access in ASP.NET 2.0 Bradley Millington Program Manager Web Platform and Tools.

Slides:



Advertisements
Similar presentations
Malek Kemmou Technology Architect, Application Platform Microsoft Middle East and Africa Overview of ASP.NET 2.0.
Advertisements

Advanced Performance Techniques in ASP.NET 2.0 William Zhang, Ph.D. Senior Consultant Microsoft Consulting Services.
Internetteknologi (ITNET2) Presentation 21: ASP.NET Advanced.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
User Controls, Master Pages, GridView. Content User Controls Styles, Themes, Master Pages Working with Data GridView Muzaffer DOĞAN - Anadolu University2.
Chapter 9 Customizing Data with Web Controls. ASP.NET 2.0, Third Edition2.
Bind Controls to Data by Using Data-Binding Syntax Web Development Fundamentals LESSON 2.5.
Microsoft Dynamics AX 2009 Integration and Development with.NET Framework Enterprise Portal.
Unit 5: Building Presentation Layer Applications with ASP.NET 2.0.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
Introduction to Database Processing with ADO.NET.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Tips and Tricks with ASP.NET 2.0 Bradley Millington Program Manager Web Platform and Tools.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Membership, Role Manager and Profile Membership, Role Manager and Profile Matt Gibbs ASP.NET Development Manager.
SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence.
Philip Wolfe Senior Consultant Sogeti Session 3 - Leveraging Data in ASP.NET 2.0 (Level 200)
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
Membership in ASP.Net...if only Presented by: Patrick Hynds President, CriticalSites Microsoft Regional Director.
Chapter 9 Using the SqlDataSource Control. References aspx.
Databases and LINQ Visual Basic 2010 How to Program 1.
Chapter 10 Managing Data with ASP.NET. ASP.NET 2.0, Third Edition2.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
ASP.NET Part 4 Instructor: Charles Moen CSCI/CINF 4230.
WEB325 Building Data-Driven Web Sites in ASP.NET 2.0 Rob Howard Telligent Corporation.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
ASP.Net Web Applications. Characteristics of a typical data driven web application Web Server HTML Graphics Active-X Java Applets HTTP Request ADO / JDBC.
Enticy GROUP THE A Framework for Web and WinForms (Client-Server) Applications “Enterprise Software Architecture”
State Management. What is State management Why State management ViewState QueryString Cookies.
Overview of Data Access MacDonald Ch. 15 MIS 324 Professor Sandvig.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
Building Data-Driven ASP.NET Web Forms Apps Telerik Software Academy ASP.NET Web Forms.
Building Data Visualization Solutions with Visio 2007 Paul Holdaway Microsoft Consulting Services (UK)
Tom Castiglia Hershey Technologies
CIS 375—Web App Dev II ASP.NET 10 Database 2. 2 Introduction to Server-Side Data Server-side data access is unique in that Web pages are basically ___________.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Malek Kemmou Technology Architect, Application Platform Microsoft Middle East and Africa Using Visual Studio 2005 to Build Data- Driven.
Microsoft SharePoint Server 2010 for the Microsoft ASP.NET Developer Yaroslav Pentsarskyy
Ventsislav Popov Crossroad Ltd.. 1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Entity Data Model and ADO.NET.
Meeting #6 – April 2011 – Web-Technologies Homework Assignments Svetlin Nakov Telerik Corporation
Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. Data Binding in ASP.NET.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Chapter 8 Working With Databases in ASP.NET. Listing 8.1 – ShowListControls Uses The SqlDataSource control for estabishing database connectivity and.
ASP.NET OPTIMIZATION. Why Optimize? $$$ Whether you build applications for customers or not, enhanced applications save money.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflows can be triggered by inputs that are designed to execute code, or alter the way the program.
TRAINING SESSIONS.NET Controls.  Standard Controls  Label  Textbox  Checkbox  Button, Image Button, Image control  Radio Button  Literal  Hyperlink.
Reference: “ASP.NET 2.0 Illustrated” by Alex Homer and Dave Sussman. -ch3 illustrated book
Ventsislav Popov Crossroad Ltd.. 1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Entity Data Model and ADO.NET.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflow Analysis of Buffer Overflow Attacks.
5-1 VISUAL J++ Colorado Technical University IT420 Tim Peterson.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
Module 10: Data Access in ASP.NET. Overview Overview of the ASP.NET Data Access What is Data Access List of Data Source Control What is Data Bound How.
Developing Custom ASP.NET Providers For Membership And Role Manager Stefan Schackow PRS404 Program Manager – Web Platform and Tools Microsoft Corporation.
ASP.NET 2.0 Mohammed Abdelhadi Developer.NET Evangelist Microsoft Corporation.
Working with Data Lesson 4. Objectives DataSource Controls A requirement for most modern Web sites is that they be dynamic. –Static pages are not often.
Introduction to Database Processing with ADO.NET
Current Popular IT I Pertemuan 5
Introduction to Database Processing with ADO.NET
Visual Basic 2010 How to Program
PROG Advanced Web Apps 5/23/2018 Notes on ADO.NET (1) Wendi Jollymore, ACES.
z/Ware 2.0 Technical Overview
Avalon – Using Data In Your Applications
test slide
Using List Controls with SQL Server
Web Development Using ASP .NET
Visual Studio + SQL Server Is Better
Visual Studio 2005 IDE Features
Presentation transcript:

Data Access in ASP.NET 2.0 Bradley Millington Program Manager Web Platform and Tools

Visual Web Developer 2005 & SQL Server 2005 –All you need to build rich data-driven apps! –Free Express Editions of both products ASP.NET Data Controls –Enable declarative data binding in ASP.NET 2.0 Scenarios Covered –Creating and connecting to a database in VS –Selecting and displaying data in a web page –Sorting, paging, updating, deleting, inserting data –Caching, filtering, master-details, parameters –Binding to business objects (DAL, BLL) –Data binding in custom templated UI –Hierarchical data (XML, SiteMap) Agenda

ASP.NET 2.0 and Data Controls Data access/presentation too hard in ASP.NET V1 –No declarative model for data acquisition/manipulation –Common scenarios required 100s of lines of code 2.0 provides easy and powerful declarative model –Handle stateless Web model for data scenarios –Do not require developer to be aware of page lifecycle events –Enable rich and pluggable data access storage providers Common UI scenarios with little to zero code –Selecting and displaying data –Sorting, paging, caching data –Updating, inserting, deleting data –Filtering, master-details (parameterization)

ASP.NET 2.0 and Data Controls Data Source Controls –Non-UI controls (no rendering) –Represent different backend data sources Databases, Business Objects, XML, or Web Services –Can cache, sort, page, filter, update, delete, insert data –Expose data through tabular or hierarchical interfaces Data-bound Controls –UI controls to render data GridView, DetailsView, FormView, TreeView, Menu –Auto-bind to data exposed from a data source –Fetches data at the appropriate time in lifecycle –Can take advantage of data source capabilities

Database XML Document Data-bound Control Data Source Control Business Object … Data Control Types

Binding to Databases with SqlDataSource demo Bradley Millington Program Manager Web Platform and Tools

Configured Connection Strings Persistence and declarative referencing of connection- strings from Web.Config –Avoid hard-coding within pages/code –Can be optionally encrypted VS supports at design time –Promote use for best practices –Enable optional encrypting of values in config Flexible Admin Support: –MMC Admin Tool Support –Configuration API Support

<connectionStrings> <add name="pubs“ ProviderName=“…” <add name="pubs“ ProviderName=“…” connectionString=“…” /> connectionString=“…” /></connectionStrings> ” SelectCommand=“select au_id from authors” runat=“server”/> ” SelectCommand=“select au_id from authors” runat=“server”/> Web.config: Page.aspx: Dim connstr As String = ConfigurationSettings.ConnectionStrings(“pubs”) Code.vb: Config Connection Strings

Most applications encapsulate data logic from presentation layer as a best practice –Embedding SQL code in a page is not ideal ObjectDataSource enables declarative binding to middle-tier objects –Select, update, insert, delete, filter and cache data –Supports custom paging and sorting Binding to Objects

Select method can return any Object or IEnumerable list, collection, or array GetProducts() -> ProductCollection GetProductsDataSet() -> DataSet GetProduct (int productId) -> Product Update, Insert, Delete methods take individual fields or data item object UpdateProduct (int id, String name, double price, bool inStock) UpdateProduct (Product p) // p.Name, p.Price, p.InStock … DeleteProduct (int id) Property or parameter names must match selected fields for GridView/DetailsView automatic updates/deletes/inserts Binding to Objects

Web Page DataSourceID = ObjectDataSource1 Northwind Database OrdersComponent OrderItemsComponent CompaniesComponent <asp:ObjectDataSource ID = ObjectDataSource1 TypeName = OrdersComponent SelectMethod = GetOrders UpdateMethod = UpdateOrder DeleteMethod = DeleteOrder Returns IEnumerable of Orders Order.OrderID Order.OrderName Order.OrderDate Binding to Objects

Binding to Objects with ObjectDataSource demo Bradley Millington Program Manager Web Platform and Tools

Data Source Paging Previous example does paging in UI layer –ObjectDataSource returns all data rows –GridView performs paging by rendering subset of rows Paging also supported on data source interface –Select (int startRowIndex, int maxRows) –Can be implemented in user-defined stored proc or custom method Data-bound controls (e.g., GridView) can use data source paging, if supported by data source –Don’t need to page in the UI layer –Useful (required) for large amounts of data

Under the Hood: Updates, Inserts, Deletes GridView extracts values from input controls, keys from viewstate (DataKeyNames) Dictionaries passed to data source operation –Update: Keys, Values [, OldValues] –Delete: Keys [, OldValues] –Insert: Values Data source applies values as parameters to command or method –Merged with any statically defined parameters –Names of parameter values match selected fields –Can optionally set format string to differentiate Keys, OldValues from new Values: OldValuesParameterFormatString=“original_{0}”

ID Name State GridView: DataKeyNames = ID <asp:ObjectDataSource ID = ObjectDataSource1 TypeName = ContactsComponent SelectMethod = GetContact UpdateMethod = UpdateContact Under the Hood: Updates

ID0 NameBradley CompanyMicrosoft GridView: DataKeyNames = ID ID0 ViewState GetContact (ID) [Edit] Request.QueryString[“ContactID”] Under the Hood: Updates

ID0 NameBrad CompanyMicrosoft UpdateContact (ID, Name, Company) GridView: DataKeyNames = ID ID0 ViewState ID0 Keys NameBrad CompanyMicrosoft Values NameBradley CompanyMicrosoft OldValues [Update] Under the Hood: Updates

ID0 NameBradley CompanyMicrosoft GridView: DataKeyNames = ID ID0 ViewState [Edit] UpdateContact (ID, Name, Company, Original_ID) Under the Hood: Updates

ID1 NameBrad CompanyMicrosoft UpdateContact (ID, Name, Company, Original_ID) GridView: DataKeyNames = ID ID0 ViewState ID0 Keys ID1 NameBrad CompanyMicrosoft Values NameBradley CompanyMicrosoft OldValues [Update] OldValuesParameterFormatString = “Original_{0}” Under the Hood: Updates

Programmability And Events Creating, Created –Raised before/after object instantiated –Can assign to ObjectInstance Selecting, Filtering, Updating, Deleting, Inserting –Raised before operation –Can optionally cancel event –Can validate and manipulate parameters Selected, Updated, Inserted, Deleted –Raised after operation complete –Can check and handle exceptions –Can obtain return values and out params Disposing –Raised prior to releasing object –Dispose() will be called if object implements IDisposable –Can optionally cancel

Data Source Events Sub MySource_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs) Dim cmd As System.Data.SqlClient.SqlCommand = e.Command cmd.Parameters(“UserId”).Value = User.Identity.Name End Sub Page.aspx.vb Page.aspx

Filtering and Master-Details Select Method or Command may be parameterized GetCustomersByCountry (int countryCode) -> CustomersCollection GetOrdersForCustomer (String customerId) -> OrdersCollection GetProduct (int productId) -> Product Data source parameter collections enable declarative associations to values –QueryStringParameter –ControlParameter –SessionParameter –FormParameter –CookieParameter –ProfileParameter –Static Parameter

Web Page Northwind Database Northwind Database OrdersComponent OrderItemsComponent CompaniesComponent <asp:ObjectDataSource ID = ObjectDataSource1 TypeName = OrdersComponent SelectMethod = GetOrdersBy Orders.aspx?company=Microsoft Filtering Data

Web Page Northwind Database Page Developer API <asp:ObjectDataSource ID = ObjectDataSource2 TypeName = CompaniesComponent SelectMethod = GetCompanies Northwind Database OrdersComponent OrderItemsComponent CompaniesComponent <asp:ObjectDataSource ID = ObjectDataSource1 TypeName = OrdersComponent SelectMethod = GetOrdersBy Filtering Data

Web Page Northwind Database Northwind Database OrdersComponent OrderItemsComponent CompaniesComponent <asp:GridView ID = GridView1 AutoGenerateSelectButton = true <asp:ObjectDataSource ID = ObjectDataSource2 TypeName = OrdersComponent SelectMethod = GetOrderBy Master-Details (1 Page)

Details Page Northwind Database Northwind Database OrdersComponent OrderItemsComponent CompaniesComponent <asp:GridView ID = GridView1 Master Page <asp:ObjectDataSource ID = ObjectDataSource2 TypeName = OrdersComponent SelectMethod = GetOrderBy Master-Details (2 Page)

Filtering and Master-Details demo Bradley Millington Program Manager Web Platform and Tools

Data Binding In Templates V1 data binding syntax too verbose – Simplified data binding syntax in ASP.NET 2.0 – // 1-way databinding – // 2-way databinding New two-way data binding syntax –Enables templated controls to retrieve input values, passed to automatic updates, inserts, deletes –Supported in GridView, DetailsView controls (TemplateField) –Support in new FormView control (fully-templated DetailsView) –Not supported for DataList (V1 control)

Data Binding in Templates demo Bradley Millington Program Manager Web Platform and Tools

Caching Data Caching is a best practice, but many developers don’t do this – it’s too hard in V1! Data sources can automatically cache data –Manages cache key and dependencies for you –Completely transparent to data-bound controls Can also manage caching yourself in business object layer

SQL Cache Invalidation Retains cache entry until database table changes –Only invalidates when backend data is stale Built on SQL Server 2005 notifications –Supported on SQL7, SQL2k, or SQL Express via polling Enabled with SqlCacheDependency property on OutputCache directive and data source controls –SqlDataSource supports notifications or polling –ObjectDataSource supports polling only Can use still use notifications in DAL/BLL code <asp:SqlDataSource … EnableCaching=“true” CacheDuration=“Infinite” SqlCacheDependency= “conn:table|CommandNotification”

Data Source Caching demo Bradley Millington Program Manager Web Platform and Tools

Hierarchical Data Hierarchical data sources –Expose data as parent-child relationships – Hierarchical data-bound controls –Use a navigator to walk the tree structure – Can also bind tabular (list) controls to hierarchical data –Only top-level data items are rendered

Hierarchical Data Can also bind to XML in a template –Can bind anywhere in the hierarchy New XPath databinding syntax –Returns simple value, e.g., “Fiction” New XPathSelect syntax –Returns a list, e.g., IEnumerable of book elements –Can be enumerated directly, or bound to the DataSource property of a list control

Binding to Hierarchical Data demo Bradley Millington Program Manager Web Platform and Tools

Summary Visual Web Developer Express and SQL Server Express make it easy to build data-driven apps! ASP.NET 2.0 data source controls dramatically simplify data-binding over v1.x Integrates easily with middle-tier data components and business objects Retains the flexibility of v1.x for complex scenarios requiring code Provides a model that third-party data providers can easily extend

Resources My Slides and Demos – ASP.NET 2.0 Quickstarts – ASP.NET Forums – Nikhil Kothari's Blog –