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 ___________.

Slides:



Advertisements
Similar presentations
Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
Advertisements

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.
Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Introduction to Database Processing with ADO.NET.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
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 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Stored Procedures Dr. Ralph D. Westfall May, 2009.
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.
CIS 375—Web App Dev II ASP.NET 2 Introducing Web Forms.
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.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
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.
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 4. 2 Overview Data Binding Data Providers Data Connection Data Manipulations.
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,
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
UNIT 9.2 Learning Objectives A Real world Application of Databases – The Money Ball Example The Money Ball Example Data Warehouses – The Role of Data Warehouses.
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.
UNIT 9.2: Learning Objectives Agile Development – Bruce Feiler on Agile Programming Database access from code – Database Cycle Review – SQL Command Types.
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
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.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
CHAPTER EIGHT Accessing Data Processing Databases.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with Disconnected Data The DataSet and SqlDataAdapter ADO.NET - Lesson.
Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. Data Binding in ASP.NET.
DEV305 Presenting Data with the ASP.NET DataGrid Control Ken Getz Senior Consultant MCW Technologies, LLC.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
ASP.NET Rina Zviel-Girshin Lecture 5
Session 8: ADO.NET. Overview Overview of ADO.NET What is ADO.NET? Using Namespaces The ADO.NET Object Model What is a DataSet? Accessing Data with ADO.NET.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Mauricio Featherman, Ph.D. Washington St. University
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
CIS 375—Web App Dev II ASP.NET 3 Working With Server Controls.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
HNDIT Rapid Application Development
2314 – Programming Language Concepts Introduction to ADO.NET.
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
C# .NET Software Development
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
SQL Triggers, Functions & Stored Procedures Programming Operations.
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
Unit 9.2 Database access from code Database Cycle Review
VB.NET Using Database.
Unit 9.3 Learning Objectives Review database access in code
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
Chapter 10 Accessing Database Files
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Presentation transcript:

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 ___________. This presents some difficult challenges when trying to perform database transactions. The __________ control can help manage these challenges, allowing you to concentrate more on your application logic and less on the details of state management and event handling.

3 Connections, Commands, and Datasets 1 The common language _________ provides a complete set of managed data access APIs for data- intensive application development. These APIs help to abstract the data and present it in a consistent way regardless of its actual source (SQL Server, OLEDB, XML, and so on). There are essentially three objects you will work with most often: A __________ represents a physical connection to some data store. A __________ represents a directive to retrieve from (select) or manipulate (insert, update, delete) the data store. A __________ represents the actual data an application works with.

4 Namespaces To give your page access to the classes you will need to perform SQL data access, you must import the System.Data and System.Data.SqlClient namespaces into your page.

5 SQL Query To perform a select query to a SQL database, you create a SqlConnection to the database passing the connection string, and then construct a SqlDataAdapter object that contains your query statement. Dim myConnection As New SqlConnection( _ "server=(local)\NetSDK;database=pubs;Integrated Security=SSPI") Dim myCommand As New SqlDataAdapter("select * from Authors", myConnection) To populate a DataSet object with the results from the query, you call the command's ______ method. Dim ds As New DataSet() myCommand.Fill(ds, "Authors")

6 SqlDataReader For Web applications, you are usually performing short operations with each request (commonly to simply display the data). You often don't need to hold a ________ object over a series of several requests. For situations like these, you can use a SqlDataReader. Dim myCommand As SqlCommand = New SqlCommand("select * from Authors", myConnection) myConnection.Open() Dim dr As SqlDataReader = myCommand.ExecuteReader()... myConnection.Close()

7 SqlCommand When performing commands that do not require data to be returned, such as inserts, updates, and deletes, you also use a SqlCommand. Dim myConnection As New SqlConnection( "server=(local)\NetSDK;database=pubs;Integrated Security=SSPI") Dim myCommand As New SqlCommand("UPDATE Authors SET phone='(800) ' WHERE au_id = ' '", myConnection) myCommand.Connection.Open() myCommand.ExecuteNonQuery() myCommand.Connection.Close()

8 Binding SQL Data to a DataGrid 1 The following sample shows a simple select query bound to a DataGrid control. The DataGrid renders a table containing the SQL data. DataGrid1.aspx [Run Sample] | [View Source]Run SampleView Source The DefaultView property represents the current state of a table within a DataSet, including any changes which have been made by application code. After setting the DataSource property, you call DataBind() to populate the control. MyDataGrid.DataSource=ds.Tables("Authors").DefaultView MyDataGrid.DataBind()

9 Binding SQL Data to a DataGrid 2 An alternative syntax is to specify both a DataSource and a DataMember. In this case, ASP.NET automatically gets the DefaultView for you. MyDataGrid.DataSource=ds MyDataGrid.DataMember="Authors" MyDataGrid.DataBind() You can also bind directly to a SqlDataReader. In this case you are only displaying data, so the forward-only nature of the SqlDataReader is perfectly suited to this scenario, and you benefit from the performance boost that SqlDataReader provides. DataGrid1.1.aspx [Run Sample] | [View Source]Run SampleView Source

10 Performing a Parameterized Select 1 You can also perform a parameterized select using the SqlDataAdapter object. The following sample shows how you can modify the data selected using the value posted from a select HtmlControl. DataGrid2.aspx [Run Sample] | [View Source]Run SampleView Source

11 Performing a Parameterized Select 2 The SqlDataAdapter maintains a Parameters collection that can be used to replace variable identifiers (denoted by an “___" in front of the name) with values. You add a new SqlParameter to this collection that specifies the name, type, and size of the parameter, and then set its Value property to the value of the select. myCommand.SelectCommand.Parameters.Add(New SqlDbType.NVarChar, 2)) = MySelect.Value

12 Performing a Parameterized Select 3 DataGrid2.aspx statically populates the values of the select box, but this will not work well if those values ever change in the database. Because the select HtmlControl also supports an IEnumerable DataSource property, you can use a ________ query to dynamically populate the select box instead, which guarantees that the database and user interface are always in sync. The following sample demonstrates this process. DataGrid3.aspx [Run Sample] | [View Source]Run SampleView Source

13 Inserting Data in a Database 1 Add a simple input _______ to the page. Execute an insert command in the form submit _______ handler. Use the command object's Parameters collection to populate the command's values. Check to make sure the required values are not null before attempting to insert into the database. Execute the insert command inside of a __________ block, just in case the primary key for inserted row already exists. DataGrid4.aspx [Run Sample] | [View Source]Run SampleView Source

14 Inserting Data in a Database 2 Instead of explicitly checking the input values, you could have just as easily used the _________ controls provided with ASP.NET. Note that using the RegEx Validator provides the additional benefit of checking the format for certain kinds of fields. DataGrid5.aspx [Run Sample] | [View Source]Run SampleView Source

15 Updating Data in a Database 1 To allow rows to be edited, the DataGrid supports an integer EditItemIndex property, which indicates which ______ of the grid should be editable. When this property is set, the DataGrid renders the row at that index as text input boxes instead of simple ________. The DataGrid can contain an EditCommandColumn that renders ______ for firing three special events: EditCommand, UpdateCommand, and CancelCommand.

16 Updating Data in a Database 2 On the DataGrid tag itself, you wire event _________ to each of the commands fired from the EditCommandColumn. The DataGridCommandEventArgs argument of these handlers gives you direct access to the _______ selected by the client, which you use to set the DataGrid's EditItemIndex. Performing an update query requires that you know the ___________ in the database for the row you wish to update. To support this, the DataGrid exposes a DataKeyField property that you can set to the field name for the primary key. DataGrid6.aspx [Run Sample] | [View Source]Run SampleView Source

17 Updating Data in a Database 3 One problem with the preceding example is that the primary key field (au_id) also renders as a text input box when a row is editable. You can disable this column from rendering as a text box by specifying exactly what each column looks like for the editable row. You do this by defining each row in the DataGrid's _________ collection, using the BoundColumn control to assign data fields with each column. DataGrid7.aspx [Run Sample] | [View Source]Run SampleView Source

18 Updating Data in a Database 4 You can also specify a TemplateColumn, which gives you complete control over the contents of the column. The following sample demonstrates using the TemplateColumn control to render the "State" column as a drop-down list and the "Contract" column as a check box ____________. DataGrid8.aspx [Run Sample] | [View Source]Run SampleView Source The following sample adds Validator controls to the columns to check the ______ input before attempting to perform the update. DataGrid9.aspx [Run Sample] | [View Source]Run SampleView Source

19 Deleting Data in a Database Another control that can be added to the DataGrid's Columns collection is the ButtonColumn control. ButtonColumn supports a CommandName property that can be set to Delete. On the DataGrid, you _____ an event handler to the DeleteCommand, where you perform the delete operation. DataGrid10.aspx [Run Sample] | [View Source]Run SampleView Source

20 Sorting Data from a Database 1 While the DataGrid control doesn't explicitly sort its data for you, it does provide a way to call an event handler when the user clicks a column header, which you can use to sort the data. When the DataGrid's AllowSorting property is set to true, it renders __________ for the column headers that fire a Sort command back to the grid. You set the OnSortCommand property of the DataGrid to the handler you want to call when the user clicks a column link.

21 Sorting Data from a Database 2 The name of the column is passed as a SortExpression property on the DataGridSortCommandEventArgs argument, which you can use to set the Sort property of the DataView bound to the grid. DataGrid11.aspx [Run Sample] | [View Source]Run SampleView Source When using BoundColumn controls, you can explicitly set the SortExpression property for each column, as demonstrated in the following sample. DataGrid12.aspx [Run Sample] | [View Source]Run SampleView Source

22 Working with Master-Detail Relationships A very common Web-based interface is one in which a row of data can be selected that navigates the client to a “________" page. To accomplish this using the DataGrid, you can add a HyperLinkColumn to the __________ collection, which specifies the details page to which the client will navigate when the link is clicked. On the details page, you retrieve the ___________ argument and perform a join select to obtain details from the database. DataGrid13.aspx [Run Sample] | [View Source]Run SampleView Source Columns

23 Writing and Using Stored Procedures Using stored procedures can reduce the cost of performing _______ database operations in an application. A stored procedure is easy to create, and can even be done using a ______ statement. CREATE Procedure GetAuthors AS SELECT * FROM Authors return GO You indicate to the SqlCommand that the CommandText is a stored procedure by setting the CommandType property. DataGrid14.aspx [Run Sample] | [View Source]Run SampleView Source

24 Accessing XML-based Data The DataSet supports a ReadXml method that takes a FileStream object as its parameter. Each TableName section corresponds to a single _____ in the table. DataGrid17.aspx [Run Sample] | [View Source]Run SampleView Source You can also read the data and _________ separately, using the ReadXmlData and ReadXmlSchema methods of the DataSet. DataGrid18.aspx [Run Sample] | [View Source]Run SampleView Source