Chapter 81 Building Data-Driven Web Applications Introduction to ASP.NET By Kathleen Kalata.

Slides:



Advertisements
Similar presentations
Chapter 3 – Web Design Tables & Page Layout
Advertisements

Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
1.NET Web Forms DataGrid © 2002 by Jerry Post. 2 Data Grid Has Many Uses  The grid uses HTML tables to display multiple rows of data. It is flexible.
Jeopardy Objects Navigation Buttons True/False Parts of a Report Vocabulary Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Chapter 9 Customizing Data with Web Controls. ASP.NET 2.0, Third Edition2.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
1 Chapter 12 Working With Access 2000 on the Internet.
Automating Tasks With Macros
Creating Custom Forms. 2 Design and create a custom form You can create a custom form by modifying an existing form or creating a new form. Either way,
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Using ADO.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Microsoft Visual Basic 2012 CHAPTER TEN Incorporating Databases with ADO.NET.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
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.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
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.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
Chapter 61 Managing Data Sources Introduction to ASP.NET By Kathleen Kalata.
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 71 Building Data-Driven ASP.NET Applications Introduction to ASP.NET By Kathleen Kalata.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
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 ___________.
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.
With Microsoft Office 2007 Introductory© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Introductory.
® Microsoft Office 2010 Access Tutorial 3 Maintaining and Querying a Database.
Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. Data Binding in ASP.NET.
ASP.NET - accessing the database - datareader vs dataset - datagrid vs datalist - brief look at web matrix.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
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
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 6 1 Microsoft Office Access 2003 Tutorial 6 – Creating Custom Forms.
CHAPTER 7 LESSON C Creating Database Reports. Lesson C Objectives  Display image data in a report  Manually create queries and data links  Create summary.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
ASP.NET Programming with C# and SQL Server First Edition
ADO.NET Framework.
Listing 9.1 ShowLocalConnection.aspx
VB.NET Using Database.
Microsoft Office Access 2003
Microsoft Office Access 2003
Chapter 10 ADO.
Chapter 10 Accessing Database Files
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

Chapter 81 Building Data-Driven Web Applications Introduction to ASP.NET By Kathleen Kalata

Chapter 82 Objectives In this chapter, you will: Use the DataReader object to display data Retrieve a DataSet from a database Use the DataView object to display data Sort data using the DataGrid control

Chapter 83 Objectives In this chapter, you will: Filter data using the DataGrid control Insert a new record into a database using the DataGrid control Modify an existing record in a database using the DataGrid Delete a record from a database using the DataGrid control Build a reusable VB.NET component that will retrieve a DataSet

Chapter 84 Using Data Sources within Visual Studio.NET The process of binding the data is the same regardless of the data source –DataReader - provides a read-only, direct connection to the data source –DataSet - accesses the data as multiple tables –DataTables - can have relationships defined between the DataTable Objects –DataView - retrieves a subset of one of the tables within the DataSet

Chapter 85 The DataReader Object The DataReader object is used to retrieve a read- only, non-buffered stream of data from a database. –Non-buffered means only one record at any one time is stored in memory –When the new record is read, the old record is removed from memory first –Because it’s a stream of data, it is retrieved sequentially and is read-only SqlDataReader is used with SQL Server databases OledbDataReader is used with all other databases, including Access and Oracle

Chapter 86 Create the DataReader Object Use the steps shown on pages 346 and 347 of the textbook to complete the tasks mentioned below: –Create the DataReader object, and read the data –Read method to retrieve the data stream in a forward only direction Once you have read the record, you can access the value of a column using the name of the column within quotations, or the index number The index number is the number of the column in the order in which it is retrieved. The index number for the first column is 0 –Use the Close method of the DataReader object when you have finished reading the data –Pass the CloseConnection property as a parameter when you call the Execute method of the Command object to close the connection to the DataReader

Chapter 87 Using the DataReader to Retrieve Data from a Database

Chapter 88 Building Search Queries Using SQL SQL commands retrieve a select group of records using a criterion that is used to filter the records A search condition evaluates to either true or false –Uses the WHERE keyword to identify the search condition “AND” is used to separate conditions; both search conditions must be resolved to true “OR” is used to separate conditions; only one of the search conditions needs to be resolved to true

Chapter 89 Building Search Queries Using SQL The search condition consists of an expression such as the name of a field, or it can be a string, a number, or a value passed from a form –Strings are case-sensitive when used as expressions –keyword NULL can be used to search for empty fields –Valid comparison operators include +,, <>, IS, and ISNOT

Chapter 810 Using the DataReader Object with a SQL Server Database The names of the Connection, Command, and DataReader objects are SqlConnection, SqlCommand, and SqlDataReader –The steps required to retrieve the data using the DataReader object are the same for both the OleDb and SqlClient databases –Code from DataReader.aspx, can be rewritten to support a SQL Server database using the SqlDataReader object

Chapter 811 Action Commands You can use the following SQL statements to insert, update, and delete records –INSERT command is used to add a new record Specify a value for every field or use the word “NULL” for the value Specify the fieldnames in parentheses after the table if you plan to only enter values for a subset of fields –DELETE command is used to delete one or more rows of data If you do not specify a specific record or set of records using the WHERE clause, the entire set of records is deleted –UPDATE command is used to modify one or more rows of data The keyword SET is used to assign the values to the fieldnames If you do not specify a search condition using the WHERE clause, the value is updated for all records in the database

Chapter 812 Upsizing an Access Database to SQL Server Use the Upsizing Wizard to upgrade an Access database to SQL Server for better security, performance, and user management –Access provides a report that contains information about the new database –Always print the report or save it as a text file for future reference –Locate the Upsizing Wizard from the Tools on the menu bar, point to Database Utilities –Use an account with CREATE DATABASE privileges –Always create a page to display your data to ensure that the data connections succeeded

Chapter 813 Using the DataReader Object to Display Data Display the categories list using the object Within the Page_Load procedure, create the objects, and retrieve the data using the DataReader object –Create a connection using a SQL Connection object –Use the DataReader to Read the data from the database Using the upsized database, you will create a page to display the categories list using the SqlClient DataReader object by following the steps listed on pages 355 and 356 of the textbook

Chapter 814 Using the DataReader Object with Stored Procedures Use the DataReader object with the Command Object in order to work with Stored Procedures using the processes outlined on pages 357 through 361 of the textbook –Set the CommandType procedure to CommandType.StoredProcedure The category list is bound to a hyperlink control –When the user clicks the link, the DataReaderProducts page opens –The CategoryID field is passed with the hyperlink as a querystring to the DataReaderProducts page –Then you create a stored procedure that only displays the products of the category that was clicked

Chapter 815 Using Stored Procedures to Display Data with the DataReader Object

Chapter 816 Using a Stored Procedure to Retrieve Data with the DataReader Object

Chapter 817 Steps to Insert the DataAdapter Object 1.Create the WebForm in Visual Studio.NET 2.Add a DataAdapter from the Data tab in the Toolbox 3.Select your database connection in the DataAdapter Wizard 4.Use the Query Builder to build an SQL statement. 5.Add a DataSet object from the Data tab in the toolbox 6.Use the Generate DataSet Methods from the Data menu

Chapter 818 Steps to Insert the DataAdapter Object 7.Create a DataView object 8.Assign a table to the DataView object 9. Assign the DataSource property of a data control to the DataView 10. Call the Fill method of the DataAdapter in the code behind the page 11. Bind the controls to the data source 12. Save and build the solution and view the Web page in a browser

Chapter 819 The DataAdapter, DataSet, and DataView Objects The DataAdapter, DataSet, and DataView objects are used together to retrieve data from the database If there is only one table involved, then you can simply use the default DataView object, or you can identify the table or SQL statement to use to retrieve a table for the DataView Create a DataView from the DataSet, which is a subset of one of the tables within the DataSet

Chapter 820 Using the DataView to Retrieve Data from a Database Refer to the DataTable in the DataView by the table name, or by its index position within the Tables collection using the processes illustrated on pages 363 through 365 of the textbook

Chapter 821 Customizing the DataGrid Control Customizing a DataGrid can be performed in the code behind the page, or by using the Visual Studio.NET tools Data Columns –Bound columns contain data that is bound to a column in the database and can display the data, or use the data in an expression, such as the source of an image tag –Unbound columns display content such as buttons and other form fields

Chapter 822 Paging and Sorting Data with the DataGrid Control The default sorting creates a Link Button control for the column name at the top of the column –When the user clicks the Link Button control, the DataGrid is sorted by that column –The DataGrid does not actually sort the rows –It raises a SortCommand event, which causes the data to be rebound to the DataSource Add code to sort the data if the event occurs –The sort expression is passed as an argument which is represented as e.SortExpression –Get the value that is selected as the sort key –Then rebind the DataGrid to the DataView

Chapter 823 Paging and Sorting Data with the DataGrid Control Paging displays a subset of records on a page –A navigation bar at the bottom of the page allows you to page through the data across Web pages The default number of records displayed is 10 Paging is turned off by default –The paging property of the DataGrid also raises a PageIndexChanged event when the user clicks the link button –Add the code to handle the event and retrieve the NewPageIndex property, which is the page the user wants to browse to –Set the CurrentPageIndex property to the NewPageIndex –Rebind the data to the DataGrid control

Chapter 824 Paging and Sorting Data with the DataGrid Control

Chapter 825 Filtering Data with the DataGrid Control The DataGrid filter allows you to temporarily select a subset of records from the DataGrid –The filter does not remove the data from the database, but only removes the records from the Web page –You have to set the RowFilter property of the DataView object to the SQL command that queries the DataView to retrieve the records –When the filter is removed, the records are redisplayed within the Web page –Perform the steps listed on pages 369 and 370 of the textbook to practice filtering data with the DataGrid control

Chapter 826 Building a Search Tool Using Visual Studio.NET

Chapter 827 Inserting, Modifying, and Deleting Records To maintain a database –Create new records, modify existing records, and delete records –Use sql commands –Use the methods built into the Data controls

Chapter 828 Using the DataGrid Control to Maintain a Database –AlternatingItemStyle – Identifies the style for alternating rows –EditItemStyle – Identifies the style for a row being edited –FooterStyle – Identifies the style for the footer row –HeaderStyle – Identifies the style for the header row –ItemStyle – Identifies the style for individual items within the list or control –PagerStyle – Identifies the style for the page selection controls –SelectedItemStyle – Identifies the style for the currently selected item

Chapter 829 Using the DataGrid Control to Maintain a Database HeaderText, HeaderImageURL, and FooterText properties - appear at the top and bottom of the TemplateColumn and may contain HTML elements and controls Visible property - allows you to show or hide the column SortExpression property - used to identify the column from the data source, which is used when sorting the column

Chapter 830 Using the DataGrid Control to Maintain a Database DataField property- identifies the column from the data source bound to the column DataFormatString property - identifies the formatting rules for the contents of the BoundColumn ReadOnly property -used with BoundColumns to stop the user from editing a column when the DataGrid is in edit mode ItemTemplate column - contains HTML elements and controls within the column

Chapter 831 Using the DataGrid Control to Maintain a Database TemplateColumn - provides additional content, such as HTML –EditItemTemplate property - used when the DataGrid is in edit mode HyperLinkColumn - used by the DataGrid control to bind a hyperlink to data ButtonColumn - used by the DataGrid control to insert a user defined button –ButtonType property – LinkButton (hyperlink) or PushButton (button)

Chapter 832 Adding and Deleting Records You can write code to insert or delete records, or you can use the methods built into the data controls –The table uses the ItemCommand to insert add and delete command functions –Use the DataGrid control to add and delete records from the DataSet Use a ButtonColumn that to trigger the Add and Delete record function Use a built-in TemplateColumn Use the directions shown on pages 372 through 378 of the textbook to perform these tasks and others as listed

Chapter 833 Adding and Deleting Records

Chapter 834 Adding and Deleting Records

Chapter 835 Updating the Database Using the DataGrid Control The DataGrid control uses the EditCommandColumn to help add interactivity to your DataGrid –EditCommandColumn is a button column that contains LinkButtons labeled Edit, Update, and Cancel –The EditCommandColumn also allows you to change the text of the Edit, Update, and Cancel buttons with the EditText, UpdateText, and CancelText properties –EditCommand event occurs when you click the edit button –UpdateCommand event is triggered when you click on the update button –CancelCommand is triggered when the user clicks the cancel button

Chapter 836 Updating the Database Using the DataGrid Control Event handlers –onEditCommand- onCancelCommand - onUpdateCommand

Chapter 837 Building Reusable Components Visual Basic.NET allows you to create reusable, compiled components that create objects, access stored procedures, and return data

Chapter 838 Creating a Global Variable in the Web Configuration File Create a global variable in the configuration file named Web.Config which will contain the connection string –The Web.Config is an XML-based text file –You can include comments within the file using the HTML comment tags –The appSettings tag indicates the settings for the Web site –Use the add tag to create the global application variables

Chapter 839 Creating a Visual Basic.NET Component

Chapter 840 Creating Web Pages from Reusable Visual Basic.NET Components