Introduction to ASP.NET, Second Edition2 Chapter Objectives.

Slides:



Advertisements
Similar presentations
17. Data Access ADO.Net Architecture New Features of ADO.NET
Advertisements

Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Chapter 10 ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a programming interface to access data in a database.
Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.
Introduction to Database Processing with ADO.NET.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Using Visual Basic 6.0 to Create Web-Based Database Applications
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.
Managing MS SQL Server ® Data Sources in VS.NET ASP.NET.
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.
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.
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
Chapter 9 Using the SqlDataSource Control. References aspx.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
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.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Chapter 61 Managing Data Sources Introduction to ASP.NET By Kathleen Kalata.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Chapter 81 Building Data-Driven Web Applications Introduction to ASP.NET By Kathleen Kalata.
Using Visual Basic 6.0 to Create Web-Based Database Applications
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.
Advanced Visual Basic th Edition Chapter 3: Using SQL Server Databases (c) 2007 Pearson Education Inc. All rights reserved. You may modify and copy.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
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.
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
CHAPTER EIGHT Accessing Data Processing Databases.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
Chapter 3 Introduction to ADO.NET 3.1 The ADO and ADO.NET ActiveX Data Object (ADO) is developed based on Object Linking and Embedding (OLE) and Component.
Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010.
ASP.NET - accessing the database - datareader vs dataset - datagrid vs datalist - brief look at web matrix.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
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)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
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,
HNDIT Rapid Application Development
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
Module 4 Introduction ADO.NET.
1 Database Programming with ADO.NET Kashef Mughal.
Module 2: Using ADO.NET to Access Data. Overview ADO.NET Architecture Creating an Application That Uses ADO.NET to Access Data Changing Database Records.
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.
ADO .NET from. ADO .NET from “ADO .Net” Evolution/History of ADO.NET MICROSOFT .NET “ADO .Net” Evolution/History of ADO.NET History: Most applications.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
Lecture 6 VB.Net SQL Server.
Active Data Objects Binding ASP.NET Controls to Data
VB.NET Using Database.
Tonga Institute of Higher Education
Chapter 8 Working with Databases and MySQL
Chapter 10 ADO.
Chapter 10 Accessing Database Files
Active Data Objects Binding ASP.NET Controls to Data
Presentation transcript:

Introduction to ASP.NET, Second Edition2 Chapter Objectives

Introduction to ASP.NET, Second Edition3 Overview of the ADO.NET Framework Universal Data Access Model (UDA) – Data can be shared across different applications and platforms ActiveX Data Object Model (ADO) – Provides objects that interface with the database – Separates the process of connecting to the data source from the manipulation of the data – Ability to write code that can transfer between applications

Introduction to ASP.NET, Second Edition4 General Steps for Using Web Databases 1.Build your database tables and queries 2.Create a connection to the database – The connection identifies the location of the database (the data source) and the connection method (an ODBC driver, OLE-DB provider, or an OLE-DB.NET data provider), along with any other settings such as username or password 3.Create an ASP.NET Web page 4.Add an ADO.NET connection object that connects to the database, executes commands, and returns data from the database 5.Create code that will interact with the data, display the data in an ASP.NET control, perform calculations on the data, or upload changes to the database

Introduction to ASP.NET, Second Edition5 ODBC, OLE DB, OLE DB.NET ODBC drivers and OLE DB providers provide low- level interface to the database – Interact using proprietary interface – standard to translate commands – ODBC drivers access ODBC compliant database – OLE DB providers – relational databases Access, SQL Server, and Exchange Server – OLE DB - ODBC providers - support legacy database applications – OLE DB.NET – New.NET Providers

Introduction to ASP.NET, Second Edition6.NET Data Provider

Introduction to ASP.NET, Second Edition7 ADO.NET Data Provider Managed Providers or.NET Data Providers – ASP.NET application interacts with.NET objects – SQL Server.NET data provider is used to connect to a SQL Server database Native communication method to communicate so there is a performance improvement – OLE DB.NET data provider connect to any other data source accessed via the OLE DB interface

Introduction to ASP.NET, Second Edition8 ADO.NET Data Provider (continued) ADO.NET Data Provider Objects – Connection – establishes a connection to the data source – Command – executes a command (SQL) – Parameter – send information with the command (retrieve only employees who live in Michigan) – DataReader – forward only, read only stream of data – DataAdapter – populates a DataSet DataSet – once its populated, the data remain disconnected from the database

Introduction to ASP.NET, Second Edition9.NET Managed Data Providers

Introduction to ASP.NET, Second Edition10 ADO.NET Objects SQL Server.NET data provider – Prefix ‘Sql’ – SqlConnection, SqlCommand, SqlDataReader, SqlDataAdaptor OLE-DB data provider – Prefix ‘OleDb’ – OleDbConnection, OleDbCommand, OleDbDataReader, OleDbDataAdaptor. Within the Web page, ASP.NET data controls are usually bound to DataReaders or DataSets. – DataSet is exposed, so it doesn’t matter where the data came from, or what application it will be used in.

Introduction to ASP.NET, Second Edition11 The ADO.NET Connection Object Provides the connection to the database – Requires a connection string Connection string – Provider – name of the managed provider. – Data Source - name of the server – User ID and Password - identifies authentication – Initial Catalog - name of the database

Introduction to ASP.NET, Second Edition12 The ADO.NET Connection Object (continued) SQL Server Connection String Manually configured Data Connections window of Visual Studio.NET Single string or concatenate Dim CS As String CS = "Data Source=WindamereServer; User ID=sa; PASSWORD=; Initial Catalog=MyDatabase;"

Introduction to ASP.NET, Second Edition13 The ADO.NET Command Object Identify command or a stored procedure – Connection - Connection used – CommandType - type of command Text - default, text string contains the command StoredProcedure – Name of a stored procedure – Stored procedures - commands that are stored within the database (compiled) TableDirect - specifies table to return

Introduction to ASP.NET, Second Edition14 The ADO.NET Command Object (continued) CommandText – command to execute – Written in SQL - Structured Query Language Language used to identify what records to add, delete, or modify within the database Exposes a Parameters collection of objects – Used to apply values passed to stored procedures

Introduction to ASP.NET, Second Edition15 The ADO.NET Command Object (continued) CommandText – command to execute – Written in SQL - Structured Query Language Language used to identify what records to add, delete, or modify within the database Exposes a Parameters collection of objects – Used to apply values passed to stored procedures – WHERE employeeState = “MI”

Introduction to ASP.NET, Second Edition16 The ADO.NET Command Object (continued) ExecuteReader method – Method that ‘executes’ the command and passes the results to the DataReader object ExecuteNonQuery method – Does not return rows – Used to insert, modify, and delete data – Returns an integer of the number of rows affected – Perform SQL commands CREATE TABLE, INSERT INTO

Introduction to ASP.NET, Second Edition17 The ADO.NET DataReader Object Deliver a stream of data from the database – High-performance – Read-only, forward-only stream of data Requires continual access to the database – Must remain connected until you have finished reading the stream of data

Introduction to ASP.NET, Second Edition18 The ADO.NET DataReader Object (continued) Read – Returns single row and caches each row in memory only once – Moves current record pointer to the next record Close method – Closes the DataReader object and releases the references to the rowset CommandObject.CommandBehavior property – Closes the connection - CloseConnection

Introduction to ASP.NET, Second Edition19 The ADO.NET DataReader Object (continued)

Introduction to ASP.NET, Second Edition20 The ADO.NET DataReader Object (continued) Figure 6-3 – Connection object provides ConnectionString – Command object provides SQL statements CommandType - Text CommantText - SELECT, which returns data ExecuteReader method provides DataReader as a result Parameter objects can be used

Introduction to ASP.NET, Second Edition21 The ADO.NET DataReader Object (continued) Figure 6-3 (continued) – DataReader - receive the data Contains a collection of DataRows Read method to literally read through each row Use a looping structure to repeat through the rows. – Displaying the data - data controls

Introduction to ASP.NET, Second Edition22 The ADO.NET DataReader Object (continued)

Introduction to ASP.NET, Second Edition23 The ADO.NET DataReader Object (continued) Figure 6-3 (continued) – Connection object provides ConnectionString – Command object provides SQL statements CommandType - Text CommandText - INSERT, which creates a new record ExecuteNonQuery method – returns number of rows affected Parameter objects can be used

Introduction to ASP.NET, Second Edition24 The ADO.NET DataReader Object (continued) Figure 6-3 (continued) – DataReader object Contains information returned (number rows affected) No records are returned – no data binding to controls

Introduction to ASP.NET, Second Edition25 The ADO.NET DataReader Object (continued)

Introduction to ASP.NET, Second Edition26 The ADO.NET DataAdapter and DataSet Objects DataAdaptor object – Works with Connection object to connect to data – Provides bridge between DataSet and data source Commands to manage DataSet – Automatically generated via CommandBuilder object – SelectCommand - retrieve data – InsertCommand - add a new record – UpdateCommand - modify the data within a record – DeleteCommand - permanently remove a record

Introduction to ASP.NET, Second Edition27 The ADO.NET DataAdapter and DataSet Objects (continued) Fill method - populates DataSet – Insert data SelectCommand returns into DataSet DataSet object – disconnected collection of one or more tables that are stored in memory on the server – maintains original set of data and changes – effectively a private copy of the database – does not necessarily reflect the current state

Introduction to ASP.NET, Second Edition28 The ADO.NET DataAdapter and DataSet Objects (continued) DataSet Object – DataTableCollection Collection of one or more DataTable Objects Each DataTable consists of: – DataRowCollection and DataColumnCollection » store information about the rows and columns of data – ConstraintCollection » includes information about the primary and foreign keys, and constraint rules

Introduction to ASP.NET, Second Edition29 The ADO.NET DataAdapter and DataSet Objects (continued) Primary key – No duplicate records appear in this column. Constraint rules – Field contains the correct datatype and values DataRelationCollection contains data required to maintain relationships between DataTables – Relationships can be made between DataTables – Tables are joined using the primary and foreign keys defined in the DataTable

Introduction to ASP.NET, Second Edition30 The ADO.NET DataAdapter and DataSet Objects (continued)

Introduction to ASP.NET, Second Edition31 The ADO.NET DataAdapter and DataSet Objects (continued)

Introduction to ASP.NET, Second Edition32 The ADO.NET DataAdapter and DataSet Objects (continued) Figure 6-3 – DataAdapter provides access to: Connection object provides ConnectionString Command object – in this case the commands are part of the DataAdapter (SelectCommand) DataAdapter populates DataSet – Can work with data while it’s in the DataSet, DataTables, or DataView – Bind DataSet, DataTables, or DataView to data controls within the Web page

Introduction to ASP.NET, Second Edition33 The ADO.NET DataView Object Contains the data from the DataSet – Single DataTable or subset of records DataTable - DefaultView property – Returns all the records in the DataTable – Can select a subset of records from a table – Add columns to the DataColumnCollection RowFilter property - filter a subset Sort property - sort data based upon criteria in one or more of the columns

Introduction to ASP.NET, Second Edition34 Data Related Namespaces

Introduction to ASP.NET, Second Edition35 Building Database Connections Server Explorer window - access to local and network databases and data connections – Servers node Access to the services running on the computer, such as a database server – Data Connections node Data connection to a database Graphical tool used to create a database

Introduction to ASP.NET, Second Edition36 Building Database Connections (continued) – ConnectString - connection properties – Database property - database – Type property - database application – Driver - ODBC driver, OLE-DB provider, or.NET managed data provider – State - if database is currently connected – User Name of user account that created database Creator is database owner, or dbo

Introduction to ASP.NET, Second Edition37 Building Database Connections (continued) Server property - server – Default name MSDE/SQL Server is [MachineName]\NetSDK MachineName - name of your local computer (local)\NetSDK or localhost Driver/Provider – Assumed to be SQL Server if it uses the SQLClient class - not required in the Connection String

Introduction to ASP.NET, Second Edition38 Downloading the MSDE Files (Page 275, 276) Create folder c:\MSDETempDE – Download files and extract files Download files Command Window cd C:\sql2ksp3\MSDE setup INSTANCENAME="NetSDK"  SECURITYMODE=SQL SAPWD="password" Verify files and folders installed – C:\Program Files\Microsoft SQL Server\MSSQL$NETSDK – Binn, Data, Install, and Log folder

Introduction to ASP.NET, Second Edition39 Installing the.NET Framework SDK Samples Database (Page 277, 278, 279) Samples and QuickStart Tutorials link – Set up the QuickStarts hyperlink – QuickStart installs at – Click – Start the ASP.NET QuickStart Tutorial – Click - An E-Commerce Storefront – Run Sample Create Chapter6 project View GrocerToGo database Add connection to GrocerToGo

Introduction to ASP.NET, Second Edition40 Visual Studio.NET Built-In Database Tools Visual tools to create and manipulate database – Server Explorer - creates database, tables, and stored procedures – Table Designer – create columns in tables – Query and View Editor - create database queries – SQL Editor - create and edit SQL scripts and stored procedures

Introduction to ASP.NET, Second Edition41 Creating a SQL Server Database in Visual Studio.NET (Page 282) Authentication is required for access – Windows NT – SQL Server User ID identifies users and access to objects – Each user has roles - create or modify data object – Needs permission to create database See Appendix B for working with the MSDE and troubleshooting data connection problems Create Chapter6 database

Introduction to ASP.NET, Second Edition42 The Table Designer Table Design view – create schema or table structure Column Name - Do not use blank spaces or special characters other than an underscore Data Type –convert to.NET data types when you retrieve your data using ADO.NET Allow Nulls – no value, a null value is returned – Properties Pane - will depend upon data type Table Data view – Create new row, modify or delete row

Introduction to ASP.NET, Second Edition43 The Table Designer (continued) INT data type - integer – Identity property provide a unique value for each row to locate a specific row of data – Identity Seed - shows the initial value – Identity Increment - value to increment the seed when a new row is added If seed is 1 and increment is 1, then it’s 1, 2, 3… If seed is 1 and increment is 2, then it’s 1, 3, 5…

Introduction to ASP.NET, Second Edition44 The Table Designer (continued) Primary Key – Each value must be unique within this column All rows must have a value for this column No record contains a null value for column – Row selector, Table toolbar, or Diagram menu – Yellow key at the side of the column name

Introduction to ASP.NET, Second Edition45 The Table Designer (Products Table Page 285)

Introduction to ASP.NET, Second Edition46 The Table Designer (Products Table Page 285)

Introduction to ASP.NET, Second Edition47 Creating a View with Query and View Editor Create a query in the database Change one pane, other panes updated Table Pane – add tables and select columns – Displays query visually with icons SQL Pane – generates the SQL Preview Pane – test run queries Grid Pane – select columns and criteria, just as you do when using Microsoft Access. The column name and table indicate where to retrieve the values for the column

Introduction to ASP.NET, Second Edition48 Creating a View with Query and View Editor (continued) Output property - column should be visible Sort order - indicate one or more columns to sort the results Sort type - ascending or descending Alias - display an alternate column name Criteria - conditional statement that must be met before the record can be retrieved Or - indicates an alternative condition that could be met before the record can be retrieved

Introduction to ASP.NET, Second Edition49 Creating a View with Query and View Editor (Page 290)

Introduction to ASP.NET, Second Edition50 Creating a Relationship with the Data Diagram Define relationships between tables using columns – A line is drawn from a field from one table to another to indicate fields to define the relationship Endpoints indicate type of relationship – One-to-many relationship Key at one endpoint and a figure-eight at the other – One-to-one relationship Key at each endpoint

Introduction to ASP.NET, Second Edition51 Creating a Relationship with the Data Diagram (Page 292) Create relationship between Categories and Products – One-to-many relationship – CategoryID column – One CategoryID value in Categories – Many products that have the same CategoryID

Introduction to ASP.NET, Second Edition52 Creating a Relationship with the Data Diagram (continued)

Introduction to ASP.NET, Second Edition53 Building SQL Scripts and Stored Procedures SQL command stored within the database – Already been parsed and compiled by the server More efficient than a SQL statement – Run a SQL query (SELECT, INSERT, etc) – Values can be replaced with input parameters

Introduction to ASP.NET, Second Edition54 Building SQL Scripts and Stored Procedures (continued) Input parameter – Value passed to the stored procedure Parameters are input parameters by default Must match data type and length Name always begins Input parameter is often compared to a value – Default value can be provided Must be a constant or it can be NULL Wildcard characters (*) are permitted

Introduction to ASP.NET, Second Edition55 Building SQL Scripts and Stored Procedures (continued) Output Parameters – Send values back to object that called stored procedure ReturnValue - return value passed back Called with RETURN keyword Retrieve identity column value Return – Information such as number of records affected Values can be integer, money, varchar - not text

Introduction to ASP.NET, Second Edition56 Building SQL Scripts and Stored Procedures (continued) Create and edit SQL scripts & stored procedures – Inserts skeletal stored procedure when you create a new stored procedure – Color code SQL keywords – Comments Indicated with /* and */ characters Displayed in green text – Change default behaviors Tab size, word wrapping, and line numbers Options on the Tools menu

Introduction to ASP.NET, Second Edition57 Creating Stored Procedures with the SQL Editor (Page 294) CREATE and ALTER Procedures – First line changes from CREATE PROCEDURE to ALTER PROCEDURE – Procedure has been created – Change or alter the procedure using the ALTER PROCEDURE command

Introduction to ASP.NET, Second Edition58 sp_ReorderProducts (Page 294)

Introduction to ASP.NET, Second Edition59 sp_DisplayProduct (Page 295)

Introduction to ASP.NET, Second Edition60 sp_DisplayProduct (continued)

Introduction to ASP.NET, Second Edition61 sp_InsertCat (Page 297) Name - sp_InsertCat – Use prefix sp_ to indicate it’s a stored procedure Input paramater Return the CatID value – – Return – Returns the identity column (primary key is the identity column)

Introduction to ASP.NET, Second Edition62 Sp_InsertCat (Page 297)

Introduction to ASP.NET, Second Edition63 Sp_InsertCat (Page 297)

Introduction to ASP.NET, Second Edition64 sp_SearchProducts (Page 298) Search for a matching value Input parameter – – Mapped to the ModelName column – Data type is nvarchar with Length 50 bytes Retrieve a subset of the columns from the database – WHERE clause to search for a condition that contains the string passed with the parameter – Wild card character and LIKE keyword locate any text that contains the string Run the procedure – search for Waterford

Introduction to ASP.NET, Second Edition65 sp_SearchProducts (Page 298)

Introduction to ASP.NET, Second Edition66 Modifying Stored Procedures with the SQL Query Builder (Page 300) SQL Query Builder - Query and View Editor – Code is stored in the stored procedure – Edit the blocks of code enclosed within a blue line – Right-click and click Design SQL Block Modify sp_ReorderProducts – Change QuantityAvailable criteria from < MinOnHand to <=10 – Save and Run procedure

Introduction to ASP.NET, Second Edition67 Internet Resources Microsoft MSDN Library — Microsoft UDA — Microsoft Data Access and Storage Developer Center SQL Server at Microsoft —

Introduction to ASP.NET, Second Edition68 Summary ADO.NET model allows you to connect to data sources using managed providers. –.NET application interfaces with.NET Providers ADO.NET object model – Includes Connection, Command, DataAdapter, and DataReader objects – DataAdapter is a bridge between DataSet and data source – DataReader is high-performance object that provides a stream of data.

Introduction to ASP.NET, Second Edition69 Summary DataSet – Is a disconnected set of data stored in memory. – Consists of a DataTable Collection and DataRelationCollection Visual Database Tools allow you to create and maintain your database Many Web sites provide information on data related technologies