ASP and ADO (assumes knowledge of ADO)



Similar documents
Real-World ASP.NET: Building a Content Management System

Systems Programming & Scripting

Conexión SQL Server C#

Crystal Reports. For Visual Studio.NET. Reporting Off ADO.NET Datasets

MOVING THE SENIOR DEVELOPMENT CLASS FROM WEB DEVELOPMENT TO LIFE CYCLE DEVELOPMENT A CASE FOR VISUAL STUDIO 2005

Database Communica/on in Visual Studio/C# using Web Services. Hans- Pe=er Halvorsen, M.Sc.

İNTERNET TABANLI PROGRAMLAMA- 13.ders GRIDVIEW, DETAILSVIEW, ACCESSDATASOURCE NESNELERİ İLE BİLGİ GÖRÜNTÜLEME

Security API Cookbook

C# Datenbank-Programmierung

Capturx for SharePoint 2.0: Notification Workflows

ASP.NET Programming with C# and SQL Server

Architecture design. Use of some Microsoft patterns & practices for Architecture Guidance (

Creating Form Rendering ASP.NET Applications

Ambientes de Desenvolvimento Avançados

Web Services in.net (1)

Visual COBOL ASP.NET Shopping Cart Demonstration

CRYSTAL REPORTS IN VISUAL STUDIO.NET 2003

1. Create SQL Database in Visual Studio

INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO:

1. La classe Connexion class Connexion {

I A Form és a párbeszédablakok I.1. MessageBox osztály MessageBox.Show(szöveg[,cím[,gombok[,ikon[,defaultbutton]]]]);

Mobile Device Access Simple Application Guide

Web Application Disassembly with ODBC Error Messages By David Litchfield Director of Security

DEVELOPING A PHD MONITORING TOOL USING ASP.NET AND SQL SERVER. A Report Submitted In Partial Fulfillment Of Course BITS C331 Computer Oriented Project

Sitecore Ecommerce Enterprise Edition Installation Guide Installation guide for administrators and developers

How To Develop A Mobile Application On Sybase Unwired Platform

A PROJECT REPORT ON. SkyDrive. Submitted for the partial fulfillment of the requirement for the Award of the degree of MASTER OF COMPUTER APPLICATION

Access Data Object (cont.)

Bronson Door Company Web Site

Connecting to Manage Your MS SQL Database


Using C# for Graphics and GUIs Handout #2

IISADMPWD. Replacement Tool v1.2. Installation and Configuration Guide. Instructions to Install and Configure IISADMPWD. Web Active Directory, LLC

Customer Portal User Manual Scott Logic Limited. All rights reserve Scott Logic Limited. All rights reserved

(Ch: 1) Building ASP.NET Pages. A. ASP.NET and the.net Framework B. Introducing ASP.NET Controls C. Adding Application logic to an ASP.

SQL Desktop Application For WebService in C# dr inż. Tomasz Tatoń

ASP.NET(C#) ile Kayıt Listeleme, Silme ve Düzenleme İşlemi

How To Create A Database In Araba

Parent Single Sign-On Quick Reference Guide

1.Tüm Kayıtları Getirme - Arama Yapma

Reporting works by connecting reporting tools directly to the database and retrieving stored information from the database.

Use the ADO Control in your Visual Basic 6 projects

Oracle 10G Form Builder and Report Builder

VB.NET - DATABASE ACCESS

A Step by Step Guide for Building an Ozeki VoIP SIP Softphone

Connect to an Oracle Database from within Visual Basic 6 (Part 1)

User Manual. Crystal Report Integration

AD A O.N. ET E Access Data Object

Beginning C# 5.0. Databases. Vidya Vrat Agarwal. Second Edition

Provider Express Obtaining Login Access. Information for Network Providers

VB.NET - WEB PROGRAMMING

Integrated Financial Management System Budget Distribution Process-User Manual

ASP.NET Dynamic Data

Login with other services to ASP.NET websites with TMS Cloud Pack for.net

Crystal Reports for Visual Studio.NET

Using CertAgent to Obtain Domain Controller and Smart Card Logon Certificates for Active Directory Authentication

(ENTD361 is highly recommended before taking this course)

Contactegration for The Raiser s Edge

Tutorial: Windows Mobile Application Development. Sybase Unwired Platform 2.1 ESD #2

TS: Microsoft.NET Framework 3.5, ASP.NET Application Development

How to create an template

Architecture Design Version1.0. Architecture Design CUSTOMER RELATION MANAGEMENT SYSTEM Version 1.0

Maryland MESA Database School Coordinators Login and Registration Training Handout

To be able to use web parts to create a portal-style web application

Terminology. Enabling Parent Single Sign-On. Server Configuration

Sales Person Commission

{ oledbdataadapter1.updatecommand.commandtext = "update personel set ad='" + textbox2.text + "' where id=" + textbox1.text; oledbconnection1.

Hotel, Dharamshala, Guest House, Individuals, Hospitals Form C. Form-C checked before providing services be filled and periodically submitted

Users Guide to Internet Banking Self Service Enrollment

PDshop.NET Installation Guides (ASP.NET Edition)

Lab 8: ASP.NET 2.0 Configuration API and Health Monitoring

Errors That Can Occur When You re Running a Report From Tigerpaw s SQL-based System (Version 9 and Above) Modified 10/2/2008

Database Communica/on in Visual Studio/C# using ASP.NET Web Forms. Hans- PeBer Halvorsen, M.Sc.

TARGETPROCESS HELP DESK PORTAL

ACDS AIMS Certified Database Specialist Course.

PEMBINA TRAILS SCHOOL DIVISION. Information Technology Department. Mayet Online Reports

How To Create An Easybelle History Database On A Microsoft Powerbook (Windows)

BACKING UP A DATABASE

Linking Access to SQL Server

Site Maintenance. Table of Contents

How to Apply Online Select School and Program

Introduction to ASP.NET and Web Forms

MSGCU SECURE MESSAGE CENTER

2311A: Advanced Web Application Development using Microsoft ASP.NET Course 2311A Three days Instructor-led

5 Airport. Chapter 5: Airport 49. Right-click on Data Connections, then select Add Connection.

COURSE CURRICULUM COURSE TITLE: WEB PROGRAMMING USING ASP.NET (COURSE CODE: )

All Windows Installations Guide Contents

Virtual Terminal Introduction and User Instructions

Using IRDB in a Dot Net Project

APPROVING WSU E-Forms

Transcription:

ASP.NET (2) These slides are meant to be for teaching purposes only and only for the students that are registered in CSE4413 and should not be published as a book or in any form of commercial product, unless written permission is obtained. 1

ASP and ADO (assumes knowledge of ADO) We can access a database from within a Web Application (ASP.NET program), by combining ASP.NET and ADO.NET. This results to a 3-Tier architecture. 1 st tier : client. See the GUI (front end) and interacts with it. 2 nd tier: (asp) server. Hosts the ASP.NET program. Hosts the.aspx and.cs files as well as the program(s) that perform ADO activities. Does not host the Database. Receives requests from the 1 st tier Processes requests. Becomes client to the 3 rd tier, which hosts the data base. Poses DB queries to 3 rd tier. Receives responses (query results) from 3 rd tier. Processes responses of 3 rd tier, assembles.html documents and sends results to 1 st tier. 3 rd tier: (db) server. Hosts the Database. Receives DB queries (typically in SQL) from 2 nd tier. Processes queries and generates results. Sends results to 2 nd tier. 2

begin 1 st tier (client to 2 nd tier) 3-tier architecture 2 nd tier (server to 1 st tier; client to 3 rd tier) 3 rd tier (server to 2 nd tier) Client s request received and a web page is generated. 3

1 st tier (client to 2 nd tier) 2 nd tier (server to 1 st tier; client to 3 rd tier) 3 rd tier (server to 2 nd tier) User clicks Show data button. 2 nd tier receives response and processes event: 1. Creates query 2. Submits query to 3 rd tier Receives query Process Query 4

1 st tier (client to 2 nd tier) 2 nd tier (server to 1 st tier; client to 3 rd tier) 3 rd tier (server to 2 nd tier) Receive results (and places result into DataSet). Generate results end 5

Example User is prompted for ID and password. 6

Example 1. User typed ID and password. 2. Request was sent to 2 nd tier. 3. 2 nd tier checked decided that (ID,Pass) is not valid. 7

Example 1. User typed again ID and password. 2. Request was sent to 2 nd tier. 3. 2 nd tier checked decided that (ID,Pass) is valid. 4. Responded back to 1 st tier that can now proceed to retrieve data. User presses button. 8

Example 1. Server received button event, 2. Processed event a) Create query, connection to DB, and sent query to 3 rd tier. b) Received results of query from 3 rd tier. c) Placed query results into DataGrid. d) Created web page shown here. e) Sent web page to 1 st tier. 9

The code This application has two.aspx files and two.cs files. This.cs file handles the login process. This.cs file handles the DB access process. 10

The code using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace WebApplication3ASPwithADO / <summary> / Summary description for WebForm1. / </summary> public class WebForm1 : System.Web.UI.Page protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Label Label2; protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.TextBox TextBox2; protected System.Web.UI.WebControls.Label Label3; protected System.Web.UI.WebControls.Button Button1; private void Page_Load(object sender, System.EventArgs e) 11

#region Web Form Designer generated code override protected void OnInit(EventArgs e) CODEGEN: This call is required by the ASP.NET Web Form Designer. InitializeComponent(); base.oninit(e); / <summary> / Required method for Designer support - do not modify / the contents of this method with the code editor. / </summary> private void InitializeComponent() this.textbox1.textchanged += new System.EventHandler(this.TextBox1_TextChanged); this.button1.click += new System.EventHandler(this.Button1_Click); this.load += new System.EventHandler(this.Page_Load); #endregion 12

private void Button1_Click(object sender, System.EventArgs e) string userid = TextBox1.Text; string userpassword = TextBox2.Text; string loginresult = ValidateUser(userID, userpassword); if (!loginresult.equals( "Welcome") ) If invalid login, clear Label3.Text = "INVALID LOGIN! Try again... "; textboxes and reprompt. TextBox1.Text = ""; TextBox2.Text = ""; Page_Load(this, e); reload page else load and display the ADO related form Response.Redirect( "WebForm2ForADOpartOfASPandADOApplication.aspx"); private string ValidateUser(string userid, string userpassword)!!! Usage of a second Form here. In case of valid login, if (userid.equals( "abc") && userpassword.equals( "pass")) open another Form that performs the database return "Welcome"; access. This is not necessary, but it makes the code more else modular and convenient to return "Invalid login."; write. private void TextBox1_TextChanged(object sender, System.EventArgs e) 13

WebForm2ForADOpartOfASPandADOApplication.aspx.cs using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace WebApplication3ASPwithADO / <summary> / Summary description for WebForm2ForADOpartOfASPandADOApplication. / </summary> public class WebForm2ForADOpartOfASPandADOApplication : System.Web.UI.Page protected System.Data.OleDb.OleDbDataAdapter oledbdataadapter1; protected System.Data.OleDb.OleDbCommand oledbselectcommand1; protected System.Data.OleDb.OleDbCommand oledbinsertcommand1; protected System.Data.DataSet dataset1; protected System.Web.UI.WebControls.DataGrid DataGrid1; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Label Label2; protected System.Data.OleDb.OleDbConnection oledbconnection1; private void Page_Load(object sender, System.EventArgs e) Put user code to initialize the page here 14

#region Web Form Designer generated code override protected void OnInit(EventArgs e) CODEGEN: This call is required by the ASP.NET Web Form Designer. InitializeComponent(); base.oninit(e); The connection to DB. / <summary> / Required method for Designer support - do not modify / the contents of this method with the code editor. / </summary> private void InitializeComponent() this.oledbconnection1 = new System.Data.OleDb.OleDbConnection(); this.oledbdataadapter1 = new System.Data.OleDb.OleDbDataAdapter(); this.oledbselectcommand1 = new System.Data.OleDb.OleDbCommand(); this.oledbinsertcommand1 = new System.Data.OleDb.OleDbCommand(); this.dataset1 = new System.Data.DataSet(); ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit(); oledbconnection1 this.oledbconnection1.connectionstring = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=""E:\4413 -- e- commerce course\ WINTER 2006\MySlides\_Slides _3 ADO NET slides\ado.net My code tests\mystudentsdb.mdb"";jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;jet OLEDB:SFP=False;persist security info=false;extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"; 15

oledbdataadapter1 this.oledbdataadapter1.insertcommand = this.oledbinsertcommand1; this.oledbdataadapter1.selectcommand = this.oledbselectcommand1; this.oledbdataadapter1.tablemappings.addrange(new System.Data.Common.DataTableMapping[] The query. new System.Data.Common.DataTableMapping("Table", "Enroll", new System.Data.Common.DataColumnMapping[] new System.Data.Common.DataColumnMapping("cno", "cno"), new System.Data.Common.DataColumnMapping("dname", "dname"), new System.Data.Common.DataColumnMapping("grade", "grade"), new System.Data.Common.DataColumnMapping("secno", "secno"), new System.Data.Common.DataColumnMapping("sid", "sid"))); oledbselectcommand1 this.oledbselectcommand1.commandtext = "SELECT cno, dname, sid, grade FROM Enroll WHERE (sid = 104)"; this.oledbselectcommand1.connection = this.oledbconnection1; oledbinsertcommand1 this.oledbinsertcommand1.commandtext = "INSERT INTO Enroll(cno, dname, grade, secno, sid) VALUES (?,?,?,?,?)"; this.oledbinsertcommand1.connection = this.oledbconnection1; this.oledbinsertcommand1.parameters.add(new System.Data.OleDb.OleDbParameter("cno", System.Data.OleDb.OleDbType.Integer, 0, "cno")); this.oledbinsertcommand1.parameters.add(new System.Data.OleDb.OleDbParameter("dname", System.Data.OleDb.OleDbType.VarWChar, 255, "dname")); this.oledbinsertcommand1.parameters.add(new System.Data.OleDb.OleDbParameter("grade", System.Data.OleDb.OleDbType.Double, 0, "grade")); this.oledbinsertcommand1.parameters.add(new System.Data.OleDb.OleDbParameter("secno", System.Data.OleDb.OleDbType.Integer, 0, "secno")); this.oledbinsertcommand1.parameters.add(new System.Data.OleDb.OleDbParameter("sid", System.Data.OleDb.OleDbType.Integer, 0, "sid")); 16

dataset1 this.dataset1.datasetname = "NewDataSet"; this.dataset1.locale = new System.Globalization.CultureInfo("en-US"); this.button1.click += new System.EventHandler(this.Button1_Click); this.load += new System.EventHandler(this.Page_Load); ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit(); #endregion private void Button1_Click(object sender, System.EventArgs e) Label1.Text = ".. connectiing to DB..."; oledbconnection1.open(); open DB Label1.Text += "connected!"; execute query oledbdataadapter1.fill( dataset1, "res"); Label1.Text += "... retrieved data!"; / Execute query, receive result (at 2 nd tier) and put result into dataset1. DataGrid1.DataBind(); DataGrid1.Visible = true; display results to datagrid Populate DataGrid with results (of dataset1) and make it visible. Note, this looks different from how it would be done normally in a windows application. (oledbdataadapter1.fill( dataset1, "res"); DataGrid1.SetDataBinding( dataset1, "res"); ) 17

The end 18