PART 1 CREATING THE PRODUCT CATALOG. ROADMAP FOR THIS CHAPTER To implement the departments list, you’ll start with the database and make your way to the.

Slides:



Advertisements
Similar presentations
Query Manager. QM is a collection of tools you can use to obtain information from the AS/400 database Used to –select, arrange, and analyze information.
Advertisements

Computer Monitoring System for EE Faculty By Yaroslav Ross And Denis Zakrevsky Supervisor: Viktor Kulikov.
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.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
ADO. NET. What is “ADO.Net”? ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical.
Performed by:Gidi Getter Svetlana Klinovsky Supervised by:Viktor Kulikov 08/03/2009.
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.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
DATABASICS A PRIMER ON DATA STRUCTURES. WHAT IS DATA? Everything. Everything is a datum. Seriously. Pretty much by definition*. But some data are better.
LAYING OUT THE FOUNDATIONS. OUTLINE Analyze the project from a technical point of view Analyze and choose the architecture for your application Decide.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
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.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
Stored Procedures, Transactions, and Error-Handling
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.
.NET Data Access and Manipulation ADO.NET. Overview What is ADO.NET? Disconnected vs. connected data access models ADO.NET Architecture ADO.NET Core Objects.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
MySQL Connection using ADO.Net Connecting to MySQL from.NET Languages.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
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.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Introduction to Exception Handling and Defensive Programming.
Module 7: Accessing Data by Using ADO.NET
Views Lesson 7.
ADO.NET Data Access. Page  2 SQL  When we interact with the datasource through ADO.NET we use the SQL language to retrieve,modify,update information.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Introduction to ADO.NET ADO.NET - Lesson 01  Training time: 10 minutes  Author:
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
1 11/10/05CS360 Windows Programming ADO.NET. 2 11/10/05CS360 Windows Programming ADO.NET  Behind every great application is a database manager o Amazon.
ADO.NET AND STORED PROCEDURES - Swetha Kulkarni. RDBMS ADO.NET Provider  SqlClient  OracleClient  OleDb  ODBC  SqlServerCE System.Data.SqlClient.
Microsoft FrontPage 2003 Illustrated Complete Integrating a Database with a Web Site.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Session 1 Module 1: Introduction to Data Integrity
NSF DUE ; Wen M. Andrews J. Sargeant Reynolds Community College Richmond, Virginia.
1 Intro stored procedures Declaring parameters Using in a sproc Intro to transactions Concurrency control & recovery States of transactions Desirable.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
C# .NET Software Development
Active Data Objects Using.Net ADO.Net Farooq Ahmed Amna Umber Summayya Shehzad.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 The SqlCommand Object ADO.NET - Lesson 03  Training time: 15 minutes  Author:
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
SQL Triggers, Functions & Stored Procedures Programming Operations.
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.
Stuff to memorise… "A method tells an object to perform an action. A property allows us to read or change the settings of the object."
Dynamic SQL Writing Efficient Queries on the Fly ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
.NET Data Access and Manipulation
1. Advanced SQL Functions Procedural Constructs Triggers.
Agenda for Today  DATABASE Definition What is DBMS? Types Of Database Most Popular Primary Database  SQL Definition What is SQL Server? Versions Of SQL.
ASP.NET Programming with C# and SQL Server First Edition
Dynamic SQL Writing Efficient Queries on the Fly
© 2016, Mike Murach & Associates, Inc.
Lecture 6 VB.Net SQL Server.
Dynamic SQL Writing Efficient Queries on the Fly
Chapter 10 ADO.
Chapter 11 Managing Databases with SQL Server 2000
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Presentation transcript:

PART 1 CREATING THE PRODUCT CATALOG

ROADMAP FOR THIS CHAPTER To implement the departments list, you’ll start with the database and make your way to the presentation tier: 1. You’ll create the Department table in the database. This table will store data regarding the store’s departments. Before adding this table, you’ll learn the basic concepts of working with relational databases. 2. You’ll add the GetDepartments stored procedure to the database, which (like all the other stored procedures you’ll write) is logically located in the data tier part of the application. At this step, you’ll learn how to speak with relational databases using SQL.

ROADMAP FOR THIS CHAPTER 3. You’ll create the business tier components of the departments list. You’ll learn how to communicate with the database by calling the stored procedure and sending the results to the presentation tier. 4. Finally, you’ll implement the DepartmentsList.ascx Web User Control to display a dynamic list of departments for your visitor, which is the goal of this chapter.

STORING CATALOG INFORMATION We’ll briefly discuss the main parts that make up a database table: Primary keys UNIQUE columns SQL Server data types Nullable columns and default values Identity columns Indexes

INDEXES You should keep the following in mind about indexes: Indexes greatly increase search operations on the database, but they slow down operations that change the database (delete, update, and insert operations). Having too many indexes can slow down the general performance of the database. The general rule is to set indexes on columns frequently used in WHERE, ORDER BY, and GROUP BY clauses, used in table joins, or having foreign-key relationships with other tables. Indexes are automatically created on primary key and unique table columns.

CREATING THE DEPARTMENT TABLE Add two sample data

COMMUNICATING WITH THE DATABASE The ultimate goal with the table is to get the list of department names from the database using C# code. Stored procedures are database objects that store programs written in T-SQL. Much like normal functions, stored procedures accept input and output parameters and have return values.

STORED PROCEDURES ADV. Storing SQL code as a stored procedure usually results in better performance because SQL Server generates and caches the stored procedure execution plan when it’s first executed. Using stored procedures allows for better maintainability of the data access and manipulation code, which is stored in a central place, and permits easier implementation of the three-tier architecture (the stored procedures forming the data tier).

STORED PROCEDURES ADV. Security can be better controlled because SQL Server permits setting different security permissions for each individual stored procedure. SQL queries created ad hoc in C# code are more vulnerable to SQL injection attacks, which is a major security threat. This might be a matter of taste, but having the SQL logic separated from the C# code keeps the C# code cleaner and easier to manage; it looks better to call the name of a stored procedure than to join strings to create a SQL query to pass to the database.

CREATE THE STORED PROCEDURE CREATE PROCEDURE GetDepartments AS SELECT DepartmentID, Name, Description FROM Department

ADDING LOGIC TO THE SITE The business tier (or middle tier) is said to be the brains of the application because it manages the application’s business logic. For the business tier of the departments list, you’ll implement three classes: GenericDataAccess implements common functionality that you’ll then reuse whenever you need to access the database. Having this kind of generic functionality packed in a separate class saves keystrokes and avoids bugs in the long run. CatalogAccess contains product catalog–specific functionality, such the GetDepartments method that will retrieve the list of departments from the database. BalloonShopConfiguration and Utilities contain miscellaneous functionality such as sending s, which will be reused in various places in BalloonShop.

CHOOSING TECHNOLOGIES AND TOOLS No matter which architecture is chosen, a major question that arises in every development project is which technologies, programming languages, and tools are going to be used, bearing in mind that external requirements can seriously limit your options. The system requirements and software requirements stages in the software development process will determine which technologies you must use for creating the application.

CONNECTING TO SQL SERVER The main challenge is to understand how the code that accesses the database works. The.NET technology that permits accessing a database from C# code is called ADO.NET. ADO.NET groups all.NET classes that are related to database access. Each database operation always consists of three steps: 1. Open a connection to the SQL Server database. 2. Perform the needed operations with the database and get back the results. 3. Close the connection to the database.

CONT. The class used to connect to SQL Server is SqlConnection. When creating a new database connection, you always need to specify at least three important pieces of data: The name of the SQL Server instance you’re connecting to The authentication information that will permit you to access the server The database you want to work with

EXAMPLE // Create the connection object SqlConnection connection = new SqlConnection(); // Set the connection string connection.ConnectionString = "Server=(local)\SqlExpress; " + "User ID=balloonshop; Password=ecommerce;" + "Database=BalloonShop"; // Open the connection connection.Open(); Or // Create the connection object and set the connection string SqlConnection connection = new SqlConnection("... connection string..."); // Open the connection connection.Open();

ISSUING COMMANDS AND EXECUTING STORED PROCEDURES // Create the command object SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandText = "CatalogGetDepartments"; command.CommandType = CommandType.StoredProcedure; Or // Create the command object SqlCommand command = new SqlCommand("GetDepartments", connection); command.CommandType = CommandType.StoredProcedure;

EXECUTING THE COMMAND AND CLOSING THE CONNECTION Three Execute methods of the SqlCommand class: ExecuteNonQuery ExecuteScalar ExecuteReader

EXECUTENONQUERY is used to execute a SQL statement or stored procedure that doesn’t return any records. Used when executing operations that update, insert, or delete information in the database. ExecuteNonQuery returns an integer value that specifies how many rows were affected by the connection.Open(); command.ExecuteNonQuery(); command.Close();

EXECUTESCALAR is like ExecuteNonQuery in that it returns a single value, although it returns a value that has been read from the database instead of the number of affected rows. It is used in conjunction with SELECT statements that select a single value. If SELECT returns more rows and/or more columns, only the first column in the first row is returned. E.g: SELECT COUNT(*) FROM

EXECUTEREADER is used with SELECT statements that return multiple records ExecuteReader returns a SqlDataReader object, which contains the results of the query. A SqlDataReader object reads and returns the results one by one, in a forward-only and read-only manner. The good news about the SqlDataReader is that it represents the fastest way to read data from the database, and the bad news is that it needs an open connection to operate—no other database operations can be performed on that connection until the reader is closed. Another solution is to load all the data returned by the SqlDataReader into a DataTable object which will allow you to close the database connection very quickly.

EXAMPLE Here’s a simple example of reading some records from the database and saving them to a DataTable: // Open the connection conn.Open(); // Create the SqlDataReader object by executing the command SqlDataReader reader = comm.ExecuteReader(); // Create a new DataTable and populate it from the SqlDataReader DataTable table = new DataTable(); table.Load(reader); // Close the reader and the connection reader.Close(); conn.Close();

IMPLEMENTING GENERIC DATA ACCESS CODE // Create a new database provider factory DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient"); // Create the connection object DbConnection conn = factory.CreateConnection(); // Initialize the connection string conn.ConnectionString = "... connection string..."; // Create the command object and set its properties DbCommand comm = conn.CreateCommand(); comm.CommandText = "CatalogGetDepartments"; comm.CommandType = CommandType.StoredProcedure; // Open the connection conn.Open(); // Execute the command and save the results in a DataTable DbDataReader reader = comm.ExecuteReader(); DataTable table = new DataTable(); table.Load(reader); // Close the reader and the connection reader.Close(); conn.Close();

CATCHING AND HANDLING EXCEPTIONS The general strategy to deal with runtime exceptions is as follows: If the error is not critical, deal with it in code, allowing the code to continue executing normally, and the visitor will never know an error happened. If the error is critical, handle it partially with code to reduce the negative effects as much as possible, and then let the error propagate to the presentation tier that will show the visitor a nice-looking “Houston, we have a problem” page. For the errors that you can’t anticipate, the last line of defense is still the presentation tier, which logs the error and politely asks the visitor to come back later.

TRY – CATCH – FINALLY CONSTRUCT try { // code that might generate an exception } catch (Exception ex) { // code that is executed only in case of an exception // (exception's details are accessible through the ex object) //it is optional } finally { // code that executes at the end, no matter if // an exception was generated or not //it is optional }

SENDING S To send s, you need the SmtpClient and MailMessage classes from the System.Net.Mail namespace. MailMessage has four important properties that you set before sending an From, To, Subject, and Body. When working with SmtpClient, you can set its Host property to the address of an external SMTP server; otherwise, the mail is sent through the local SMTP service in Windows.

START PRACTICE SHEET 2