Chapter 8 Working With Databases in ASP.NET. Listing 8.1 – ShowListControls Uses The SqlDataSource control for estabishing database connectivity and.

Slides:



Advertisements
Similar presentations
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Advertisements

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.
11 User Controls II Chapter Objectives You will be able to Create a realistic reusable user control. Use data binding in a user control. Change.
Bind Controls to Data by Using Data-Binding Syntax Web Development Fundamentals LESSON 2.5.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Building ASP.NET Applications 2 Lecture 3,4 T. Ahlam Algharasi 4 th Level.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
VB.NET Database Access ISYS 812. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Some Basic Database Terminology
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.
Chapter 9 Using the SqlDataSource Control. References aspx.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Databases and LINQ Visual Basic 2010 How to Program 1.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Chapter 10 Managing Data with ASP.NET. ASP.NET 2.0, Third Edition2.
Advanced Forms Lesson 10.
Server-side Scripting Powering the webs favourite services.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
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.
MSIS 5133 Advanced MIS - E-Commerce Spring 2003 Lecture 4: DotNet Technologies - Part 4 Using Controls with Databases Dr. Rathindra Sarathy.
Chapter 81 Building Data-Driven Web Applications Introduction to ASP.NET By Kathleen Kalata.
Chapter 71 Building Data-Driven ASP.NET Applications Introduction to ASP.NET By Kathleen Kalata.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 4-1 of…
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.
Ventsislav Popov Crossroad Ltd.. 1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Entity Data Model and ADO.NET.
DataSource controls in.NET How to access databases.
Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. Data Binding in ASP.NET.
Caching Chapter 12. Caching For high-performance apps Caching: storing frequently-used items in memory –Accessed more quickly Cached Web Form bypasses:
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Data-Driven - 1 © Minder Chen, Building Data-Driven Web Sites in ASP.NET 2.0.
TRAINING SESSIONS.NET Controls.  Standard Controls  Label  Textbox  Checkbox  Button, Image Button, Image control  Radio Button  Literal  Hyperlink.
11 The Repeater Control. 22 Objectives You will be able to use a Repeater Control to display data obtained with a SQL query with custom formatting.
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.
ASP Chapter 8 1. Active Server Pages Server-side technology dynamicinteractivedata-driven Enables dynamic, interactive, data-driven web pages languages.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflow Analysis of Buffer Overflow Attacks.
Data Listing Web Controls MacDonald Ch MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
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.
Unit 8.2 Learning Objectives Data Warehouses – The Role of Data Warehouses The Role of Data Warehouses – Group Exercise Accessing Data in Views – Accessing.
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.
CHAPTER 7 LESSON C Creating Database Reports. Lesson C Objectives  Display image data in a report  Manually create queries and data links  Create summary.
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.
Displaying and Updating Data
Current Popular IT I Pertemuan 5
Creating Data Base & Sql Data Source
Visual Basic 2010 How to Program
Unit 9.1 Learning Objectives Data Access in Code
PROG Advanced Web Apps 5/23/2018 Notes on ADO.NET (1) Wendi Jollymore, ACES.
Active Data Objects Binding ASP.NET Controls to Data
Unit 8.2 How data can be used Accessing Data in Views
Listing 9.1 ShowLocalConnection.aspx
VB.NET Using Database.
Using List Controls with SQL Server
Creating Data Base & Sql Data Source
Web Development Using ASP .NET
Chapter 10 Accessing Database Files
Active Data Objects Binding ASP.NET Controls to Data
Presentation transcript:

Chapter 8 Working With Databases in ASP.NET

Listing 8.1 – ShowListControls Uses The SqlDataSource control for estabishing database connectivity and query/update Includes all the list controls: – BulletedList, CheckBoxList, DropDownList, ListBox, and RadioButtonList Each List control has these properties for data binding using an SqlDataSource – DataSourceId – the ID of the SqlDataSource object – DataTextField – the name of the column from the SQL command that should be displayed

Listing 8.1 ShowListControls.aspx Each of these are subclasses of the ListControl class. ListControl is an abstract class.

Listing 8.1 ShowListControls.aspx The SQLDataSource control allows the.aspx page to set both database connections and default queries.  With this approach, database connectivity and query is part of the markup, not the code-behind

SqlDataSource Control Represents an SQL database to data-bound controls Used to establish connection to a data source and perform queries and updates to the data source. Some Properties – ConnectionString – SelectCommand – InsertCommand – UpdateCommand – DeleteCommand

ConnectionString Property <asp:SqlDataSource id="srcMovies" ConnectionString="Data Source=.\SQLExpress; AttachDbFilename=|DataDirectory|MyDatabase.mdf; Integrated Security=True;User Instance=True" SelectCommand="SELECT Title FROM Movies" Runat="server" /> The ConnectionString property’s value depends on the database server and host’s configurations. Above is the connection string from the book. For the Lab computers use the following: ConnectionString="Server=localhost;Database=MyDatabase; Trusted_Connection=Yes;"

SelectCommand <asp:SqlDataSource id="srcMovies" ConnectionString="Data Source=.\SQLExpress; AttachDbFilename=|DataDirectory|MyDatabase.mdf; Integrated Security=True;User Instance=True" SelectCommand="SELECT Title FROM Movies" Runat="server" /> The SelectCommand property’s is a SQL SELECT statement. Other properties include InsertCommand, UpdateCommand, and DeleteCommand.

List Control Data Binding Properties All List controls (databound) include these two properties: DataSourceId – the ID of the SqlDataSource object DataTextField – the name of the column from the SQL SelectCommand that should be displayed <asp:BulletedList id="BulletedList1" DataSourceId="srcMovies" DataTextField="Title" Runat="server" />

Browser’s rendering of HTML code. Note, each list contains the result of the SQL SELECT query of the associated SqlDataSource, with the Title column being displayed.

Listing 8.6 BoundGridView.aspx GridView is a databound control that renders an HTML table based on a query.

These six Web controls are more complex and can display multiple separate columns from a query. Listing 8.2 ShowTabularDataBound.aspx

Browser’s rendering of HTML code.

Tabular DataBound Controls Multiple Data Records – GridView – HTML table, one record per displayed row – DataList – HTML table, multiple records can display on a row, requires templates – Repeater – does not render an HTML table, requires templates – ListView – displayed via template; allows sorting, paging, editing Single Data Record – DetailsView – HTML Table of a single record – FormView – Single record displayed via templates, allows paging Subclasses of CompositeDataBoundControl Subclasses of DataBoundControl (newer) Not descended from DataBoundControl (older)

Using Item Templates <asp:FormView id="FormView1" DataSourceId="srcMovies" AllowPaging="true" Runat="server"> directed by ItemTemplates allow you to specify, using html and “old ASP”, specific content to display. ItemTemplate is a sub-element of the data bound Web control. <asp:Repeater id="Repeater1" DataSourceId="srcMovies" Runat="server"> directed by

Old ASP <asp:FormView id="FormView1" DataSourceId="srcMovies" AllowPaging="true" Runat="server"> directed by Before.NET, ASP tags looked like this: The Eval function call returns the value of the field identified in its argument. <asp:Repeater id="Repeater1" DataSourceId="srcMovies" Runat="server"> directed by

Listing 8.10 ShowLinks.aspx ItemTemplates can contain other tags as sub- elements.

Listing 8.13 ShowFormView.aspx EditItemTemplates can contain other tags as sub-elements, and allow for Buttons to submit data to the server. The UpdateCommand This is called a placeholder. This allows you to retrieve the data from the associated TextBox controls in the form (and DataKeyName for the primary key).

Listing 8.7 ShowControlParameter.aspx This example illustrates the use of control parameters to modify queries based on user selection from a DropDownList

Database Tables for this Example Two tables, with one-to-many relationship.

Listing 8.7 ShowControlParameter.aspx A DropDownList databound to a SqlDataSource for the dominant table in the relationship.

Listing 8.7 ShowControlParameter.aspx Clicking the button simply performs the submit to the server.

Listing 8.7 ShowControlParameter.aspx Based on the user- selected value from the DropDownList, the other SqlDataSource can customize a query. This is done through the control parameter.

Listing 8.7 ShowControlParameter.aspx A control parameter links a particular control to an item in a SelectCommand (or Update, Insert, Delete). Note: there are other types of parameters. The SelectParameters sub- element represents a collection of parameters to be used for the SelectCommand. Each SelectParameter will be associated with a placeholder in the query.

Listing 8.7 ShowControlParameter.aspx ControlParameter Properties: Name – identifies the placeholder to replace in the query ControlID – identifies the control that contains the value to put into the placeholder