Using databases ActiveX Data Objects (ADO) Connecting to a database Reading data from a database Inserting, updating and deleting records Using databases.

Slides:



Advertisements
Similar presentations
Basics of Database Programming with VB6
Advertisements

Connecting to Database 21 Feb Database Options Can use many different databases in conjunction with php. – MySql; MS Access; Oracle; etc etc Most.
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.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
Prentice Hall © COS 346 Day Agenda Capstone Progress report due Assignment 9 not corrected yet Assignment 10 posted (last one!!!) –Due.
The ADO Data Control. Universal Data Access Open Database Connectivity (ODBC) –standard for accessing data in databases OLE-DB –allows access to data.
ActiveX Data Object ISYS 562. ADO An ActiveX control ActiveX is build upon COM, a contract that defines a standard interface by which objects communicate.
Using Visual Basic 6.0 to Create Web-Based Database Applications
 ADO Object Model  Database Connection  Record Set  Query Examples  Update & Insertion Examples  An Application Example Working with Database in.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall COS 346 Day 23.
1 Active Server Pages Active Server Pages (ASPs) are Web pages ASP = server-side scripts + HTML The appearance of an Active Server Page depends on who.
Database Connectivity Session 2. Topics Covered ADO Object Model Database Connection Retrieving Records Creating HTML Documents on-the-fly.
Visual Basic Database Access BICS546. Microsoft Universal Data Access OLE DB: The OLE database protocol –Allows a program to access information in any.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 12-1 COS 346 Day 22.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
DT221/3 Internet Application Development Active Server Pages & Database Connection.
ODBC Open DataBase Connectivity a standard database access method developed by Microsoft to access data from any application regardless of which database.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 12-1 David M. Kroenke’s Chapter Twelve: ODBC, OLE DB, ADO, and ASP Part.
Interacting With Data Week 8 Connecting to the database Creating recordsets Interacting with the database.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
Interacting With Data Databases.
ADO Connect Y.-H. Chen International College Ming-Chuan University Fall, 2004.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
ActiveX Data Object (ADO) in JavaScript J.L.Wang, Yen-Cheng Chen Dept. of Infomation Management Ming-Chuan University Jan
© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 1 IT 390 Business Database Administration Unit 9:
1 VBScript Session What we learn last session?
Introduction to ADO By David R. Stevenson Consulting Software Engineer ABB Automation.
Data-Enabled Web Sites: Classibooks.com & Internet Database Technologies Colin Fukai April 4, 2000 Gonzaga University.
Database 20/2/12 Connection. 
Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design.
Using Visual Basic 6.0 to Create Web-Based Database Applications
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
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.
Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10.
File Processing Concepts – Field – combination of 1 or more characters that is the smallest unit of data to be accessed – Record – group of related fields.
Introduction to ADO Y.-H. Chen International College Ming-Chuan University Fall, 2004.
Lecture Note 10: Simple Database Techniques. Introduction –Database System –Access, SQL Server and others. –Microsoft Access - Interacting with this databases.
Visual Basic ADO Programming 56:150 Information System Design.
ASP.NET - accessing the database - datareader vs dataset - datagrid vs datalist - brief look at web matrix.
Internet Programming ASP Sara Shahzad Dept. of Computer Science UOP.
What is database?  Any Method for access info into Application from DataBase?  ODBC is standard for Accessing Data.  Problem with ODBC:  Information.
How to Connect to Database ODBC (Open Database Connectivity) ADO (ActiveX Data Object) ASP Code To Connect to Database Recordset Object Navigating through.
3-Tier Client/Server Internet Example. TIER 1 - User interface and navigation Labeled Tier 1 in the following graphic, this layer comprises the entire.
ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard set of objects to refer.
Swiss Federal Institute of Technology 1 Active Server Pages (ASP) n The simplest example: Additionally ASP may contain code (scripts, ActiveX controls)
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
ASP-12-1 Data Store Access Colorado Technical University IT420 Tim Peterson.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component.
Database Connectivity and Server-Side Scripting Chapter 12.
ADO.NET Architecture MIS3502: Application Integration and Evaluation David Schuff Adapted from material by Arnold Kurtz, David.
ODBC : Open Database Connectivity SNU OOPSLA Lab. October 2005.
Source = Table rsObject.Open tablename, Connection Object, CursorType, LockType, adCmdTable Source = Stored Procedure rsObject.Open stored procedure name,
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 6: Accessing a database with PHP Rob Gleasure robgleasure.com.
7-1 Active Server and ADO Colorado Technical University IT420 Tim Peterson.
ASP-13-1 Recordsets Colorado Technical University IT420 Tim Peterson.
1 ADO Activex Data Objects. 2 ADO ADO allows users to access data easily from many existing databases (such as Access or Paradox) From ODBC compliant.
ADO & Recordsets. ADO Description & History  ActiveX Data Objects  History  1991 ODBC  Data Access Objects (DAO) for VB developers (JET)  Remote.
Lecture 4 Manipulating Form Data using methods of Recordset and RecordsetClone in VBA Restrict data with filter 1 Rapid Application Development.
 2 Data Object Library approaches ◦ DAO (Data Access Objects)  Original access strategy (up to VB6)  Closely linked to MS Access ◦ ADO (ActiveX Data.
ASP.NET Programming with C# and SQL Server First Edition
ADO VBA Programming in Access
Working with Database in ASP
ActiveX Data Objects (ADO)
INT213 Updating the Database.
VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY.
Chapter 10 ADO.
Database Connections.
Presentation transcript:

Using databases ActiveX Data Objects (ADO) Connecting to a database Reading data from a database Inserting, updating and deleting records Using databases ActiveX Data Objects (ADO) Connecting to a database Reading data from a database Inserting, updating and deleting records Objectives (ASP)

This week’s material is from Day 15, 16 and 17 of the textbook. Read the book. You can skip those statements/sessions that are not mentioned in this lecture. This week’s material is from Day 15, 16 and 17 of the textbook. Read the book. You can skip those statements/sessions that are not mentioned in this lecture. Material

To store information through the use of a Web site, we can use cookies, the Session object and text files. All these methods have their drawbacks. Databases are specifically designed to store massive amounts of information efficiently. Many commercial databases are available, including Access, MS SQL- Server, Oracle and Informix etc. It is possible to read and modify the contents of a database through an ASP page. Relational database ? To store information through the use of a Web site, we can use cookies, the Session object and text files. All these methods have their drawbacks. Databases are specifically designed to store massive amounts of information efficiently. Many commercial databases are available, including Access, MS SQL- Server, Oracle and Informix etc. It is possible to read and modify the contents of a database through an ASP page. Relational database ? Using databases

To retrieve information from a database, you need to use a two-step process 1. Establish a connection to the database 2. Query the database, asking for information ADO provides two useful objects: the Connection object and the Recordset object. What is ADO? To retrieve information from a database, you need to use a two-step process 1. Establish a connection to the database 2. Query the database, asking for information ADO provides two useful objects: the Connection object and the Recordset object. What is ADO? Using databases

At one time, connecting to a database was difficult. Database came in a variety of formats, and you have to know low level API (Application Programming Interface) for every database you use. A universal ASP came – ODBC (Open DataBase Connectivity) was developed. Many databases were known as ODBC-compliant. Microsoft’s solution for ODBC = DAO (Database Access Objects), then RDO (Remote Data Objects), and then ADO (ActiveX Data Objects) At one time, connecting to a database was difficult. Database came in a variety of formats, and you have to know low level API (Application Programming Interface) for every database you use. A universal ASP came – ODBC (Open DataBase Connectivity) was developed. Many databases were known as ODBC-compliant. Microsoft’s solution for ODBC = DAO (Database Access Objects), then RDO (Remote Data Objects), and then ADO (ActiveX Data Objects) ActiveX Data Objects ADO

DAO, RDO, and ADO all have shortcomings. Microsoft introduced OLEDB, a COM-based data access object. COM – Component Object Model – a model for binary code developed by Microsoft OLEDB sort of replaces ODBC. It includes an ODBC driver so it is compatible with all the ODBC data source. DAO, RDO, and ADO all have shortcomings. Microsoft introduced OLEDB, a COM-based data access object. COM – Component Object Model – a model for binary code developed by Microsoft OLEDB sort of replaces ODBC. It includes an ODBC driver so it is compatible with all the ODBC data source. ActiveX Data Objects ADO

ASP Page ActiveX Data Object (ADO) OELDB ODBCAccessSQLOther Data Providers

The ADO model contains six objects Connection object - connects to data source Recordset object - work with data in a table Error object - represents an error generated by data source Field object - represents a single column in the table Command object - provides another way to create a recordset object Parameters object - contains any parameters needed by the command The ADO model contains six objects Connection object - connects to data source Recordset object - work with data in a table Error object - represents an error generated by data source Field object - represents a single column in the table Command object - provides another way to create a recordset object Parameters object - contains any parameters needed by the command ActiveX Data Objects ADO

Before you can do anything with the database, you need to connect to it. There are 2 ways to connect to a Access database. 1. Using a System DSN 2. Using a DSN-less connection A system DSN is a file that contains information about the database such as where it is and what kind of database it is. Creating a system DSN : (P511) Control Panel - ODBC - System DSN Before you can do anything with the database, you need to connect to it. There are 2 ways to connect to a Access database. 1. Using a System DSN 2. Using a DSN-less connection A system DSN is a file that contains information about the database such as where it is and what kind of database it is. Creating a system DSN : (P511) Control Panel - ODBC - System DSN Connecting to a Database

After creating a DSN (e.g. WidgetWorld.dsn to connect to c:\my documents\WidgetWorld.mdb) … You can use the connection object in ASP … (P513) Dim objConn Set objConn = Server.CreateObject (“ADODB.Connection”) objConn.ConnectionString = “DSN=WidgetWorld.dsn” objConn.Open This creates the Connection object, set the connection string, and opens the connection. objConn.Close Set objConn = Nothing This closes the connection to free the memory. After creating a DSN (e.g. WidgetWorld.dsn to connect to c:\my documents\WidgetWorld.mdb) … You can use the connection object in ASP … (P513) Dim objConn Set objConn = Server.CreateObject (“ADODB.Connection”) objConn.ConnectionString = “DSN=WidgetWorld.dsn” objConn.Open This creates the Connection object, set the connection string, and opens the connection. objConn.Close Set objConn = Nothing This closes the connection to free the memory. Using a System DSN

This is an alternative to using a System DSN (e.g. to c:\my documents\WidgetWorld.mdb) … DSN-less Connection (P512) Dim objConn Set objConn = Server.CreateObject (“ADODB.Connection”) objConn.ConnectionString = “DRIVER={Microsoft Access Driver (*.mdb)};” &_ “DBQ=C:\my documents\WidgetWorld.mdb” objConn.Open Driver = line tells the kind of database it is connecting to DBQ = line tells where on the server the database resides. This is an alternative to using a System DSN (e.g. to c:\my documents\WidgetWorld.mdb) … DSN-less Connection (P512) Dim objConn Set objConn = Server.CreateObject (“ADODB.Connection”) objConn.ConnectionString = “DRIVER={Microsoft Access Driver (*.mdb)};” &_ “DBQ=C:\my documents\WidgetWorld.mdb” objConn.Open Driver = line tells the kind of database it is connecting to DBQ = line tells where on the server the database resides. Using a DSN-less Connection

Sometimes we do not have physical access to the server. Sometimes we want the code to be able to run anywhere. (so we cannot use c:\my documents\WidgetWorld.mdb) We can use Server.MapPath to find the physical path. Dim objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &_ server.mappath("WidgetWorld.mdb") Server.MapPath will find the physical path, so the code can run anywhere on from any physical location. Sometimes we do not have physical access to the server. Sometimes we want the code to be able to run anywhere. (so we cannot use c:\my documents\WidgetWorld.mdb) We can use Server.MapPath to find the physical path. Dim objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &_ server.mappath("WidgetWorld.mdb") Server.MapPath will find the physical path, so the code can run anywhere on from any physical location. Using a DSN-less Connection

We went through 3 ways to connect to a database 1. System DSN (create it under ODBC) 2. DSN-less Connection (physical path) 3. DSN-less Connection (Server.MapPath, relative path) Now you know how to connect to a database. To work with data in the database, you need Recordset object. (P516) We went through 3 ways to connect to a database 1. System DSN (create it under ODBC) 2. DSN-less Connection (physical path) 3. DSN-less Connection (Server.MapPath, relative path) Now you know how to connect to a database. To work with data in the database, you need Recordset object. (P516) Connection to a database

The Recordset object may be used to contain a subset of the records in a table, or even all the records in the table. To instantiate the Recordset object (P516) Dim objRS Set objRS = Server.CreateObject ("ADODB.Recordset") The Open Method recordset.Open source, connection, cursortype, locktype, commandtype Source: Command Object, or string containing recognized command Connection: Connection Object, or string containing connection info cursortype: the way to move through recordset, default 0, forward, Day18 locktype: whether you can write to the table, default 1, readonly, Day 17 commandtype: how source should be evaluated, default 2, as table name The Recordset object may be used to contain a subset of the records in a table, or even all the records in the table. To instantiate the Recordset object (P516) Dim objRS Set objRS = Server.CreateObject ("ADODB.Recordset") The Open Method recordset.Open source, connection, cursortype, locktype, commandtype Source: Command Object, or string containing recognized command Connection: Connection Object, or string containing connection info cursortype: the way to move through recordset, default 0, forward, Day18 locktype: whether you can write to the table, default 1, readonly, Day 17 commandtype: how source should be evaluated, default 2, as table name The Recordset Object

Reading data from a database (P519) <% Const adCmdTable = 2 Dim objRS Set objRS = Server.CreateObject ("ADODB.Recordset") objRS.Open "tblExpenses", objConn,,, adCmdTable Do While Not objRS.EOF Response.Write "Name: " & objRS("EmployeeName") Response.Write " " objRS.MoveNext Loop objRS.Close set objRS=Nothing objConn.Close Set objConn=Nothing %>

Inserting, updating & deleting records (Day17) <% Const adLockOptimistic = 3 Const adCmdTable = 2 Dim objRS Set objRS = Server.CreateObject ("ADODB.Recordset") objRS.Open "tblUsers", objConn,, adLockOptimistic, adCmdTable objRs.AddNew objRs("FirstName") = "Gene" objRs("LastName") = "Williams" objRs(" ") = objRs("Username") = "ww123" objRs("Password") = "pass" objRs.Update objRS.Close set objRS=Nothing objConn.Close Set objConn=Nothing %>

A Simple Project 3 Diagram Announcements