INT213 Updating the Database.

Slides:



Advertisements
Similar presentations
Basics of Database Programming with VB6
Advertisements

ADO DB in Access VBA © Walter Milner 2005 Slide: 1 ADO VBA Programming in Access.
Managing Multi-User Databases (2) IS 240 – Database Management Lecture #19 – Prof. M. E. Kabay, PhD, CISSP Norwich University
1 Chapter 10 Protecting Data Integrity in a Multiuser Environment.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Persistent data storage: relational databases and ADO.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Web applications: Writing data to Databases using ASP.
ASP Application Development Session 3. Topics Covered Using SQL Statements for: –Inserting a tuple –Deleting a tuple –Updating a tuple Using the RecordSet.
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.
VBA Data Access Object. Data Access Objects DAO With DAO we can: –Run queries –Update values in database tables –Create structure of databases Tables,
Using Objects and Properties
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall COS 346 Day 23.
Web-based Programming Lanjut Pertemuan 6 Matakuliah: M0492 / Web-based Programming Lanjut Tahun: 2007.
Programming the RecordSet Object
 2004 Tau Yenny, SI - Binus M0194 Web-based Programming Lanjut Session 6.
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.
Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP.
CIS 451: ASP Recordsets Dr. Ralph D. Westfall May, 2002.
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
ASP & ADO. Connection Object An implicit connection is created when we open a recordset without a connection object. –rs.open “Customer”, "DSN = Sales”
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: Writing data to Databases using ASP.
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.
ADO Recordsets. Recordset Objects Similar to Tables and Queries: data Using VBA/VBScript you… –Open a recordset, –Locate a record –Update or add a record.
Interacting With Data Databases.
ActiveX Data Object (ADO) in JavaScript J.L.Wang, Yen-Cheng Chen Dept. of Infomation Management Ming-Chuan University Jan
1 VBScript Session What we learn last session?
Introduction to ADO By David R. Stevenson Consulting Software Engineer ABB Automation.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Database actions In this presentation… –database actions –database connections –recordsets.
Chapter 15: Using LINQ to Access Data in C# Programs.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Copyright © 2001 by Wiley. All rights reserved. Chapter 9: Introduction to Working with Databases in Visual Basic Database Concepts Relational Database.
Recordsets Chapter 7. Recordset Objects Similar to Tables and Queries: data But forms cannot be bound to them Fields cannot be bound to them But Access.
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.
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.
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.
Mark Dixon Page 1 21 – Web applications: Writing data to Databases using ASP.
Chapter 9 Building the Shopping cart Objective Creating Shopping cart using session Variable. Creating a shopping cart using a database table. Use the.
Lab 8 Data Access Using Microsoft ActiveX Data Object (ADO)
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.
ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard.
Source = Table rsObject.Open tablename, Connection Object, CursorType, LockType, adCmdTable Source = Stored Procedure rsObject.Open stored procedure name,
Module Road Map The Scope of the Problem A range of potential problems Lost Updates User A reads a record User B reads the same record User A makes changes.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 6: Accessing a database with PHP Rob Gleasure robgleasure.com.
Labtest.ASP Notes. INSERT STATUS INSERT STATUS
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.
Using databases ActiveX Data Objects (ADO) Connecting to a database Reading data from a database Inserting, updating and deleting records Using databases.
 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
Visual Basic Database Access
Visual Basic Database Programming.
Data Access Objects .
ADO VBA Programming in Access
Find, filter etc with connection to Access code internally
A Guide to SQL, Seventh Edition
ActiveX Data Objects (ADO)
The Recordset Object.
ربط الفيجوال بيسك VB مع قواعد البيانات
Chapter 6 Displaying Your Products
VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Chapter 10 ASP and Data Store Access
Working With Databases
Presentation transcript:

INT213 Updating the Database

Contents Cursors Locking Updating databases

Cursors So far, we have stepped through a Recordset in the forward direction one record at a time This technique uses the simplest cursor, the forward-Looking-Only cursor A cursor is simply a pointer that indicates your current location in the Recordset

Cursors A cursor points to a specific row BOF A cursor points to a specific row Different types of cursors can Move forward Move backward Move by several rows A cursor cannot Move before the first record (Beginning Of File) Move after the last record (End Of File) Row 1 cursor Row 2 Row n EOF

Cursor Types Cursor Constant Value Description Forward only adOpenForwardOnly Moves forward only, one by one. Fastest performing cursortype, and also the most limited. The forward-only cursor does not support the RecordCount property, and does not support the MovePrevious methods of the recordset object. Static adOpenStatic 3 The result is not updated when changes are made to the database Keyset adOpenKeyset 1 Not applicable to this course Dynamic adOpenDynamic 2 This reevaluates the query each time a new row is requested. Thus, new rows added are detected.

Scrollable Cursors All cursors, except forward-only, are scrollable This means they can move in more than just the forward direction Scrollable cursors support the methods MoveFirst – move to the first record MoveLast – move to the last record MoveNext – move to the next record MovePrevious – move to the previous record Move n – move n records forward or back

Selecting a Cursor RecordSet.Open The cursor is selected via one of the parameters used when opening the RecordSet RecordSet.Open source, (sql statement, stored procedure or table name) connection, (connection string or connection object) cursorType, (How to move through RecordSet) LockType, (Whether to read or write to a table) commandType (describes the source)

Selecting a Cursor To create a static cursor set RS = Server.CreateObject ("ADODB.Recordset") query = "SELECT * FROM Person ORDER BY lastName" RS.Open query, objConn, adOpenStatic To output a RecordSet in reverse rs.MoveLast Do While Not RS.BOF Response.Write RS("firstName") & " " & RS("lastName") & "<br>" RS.MovePrevious Loop

Adovbs.inc So far we have defined the constants for the cursor types ourselves These are actually in a file called adovbs.inc You can include this in your scripts <!--#include virtual=“adovbs.inc”--> <!--#include file=“adovbs.inc”-->

Counting Records How do you determine the number of records in a RecordSet? Have a loop Move through the RecordSet and count them Use the RecordCount property of a scrollable cursor Response.Write "The number of names is " & RS.RecordCount & "<br>"

Locking When two people try to update a record at the same time, confusion and errors result To avoid this problem, VBScript can be configured to lock the records This means that one person locks the record and updates it The other person cannot read or update the record until the first person releases their lock

Lock Types Lock Constant Description Read-only adLockReadOnly Records are read-only and cannot be modified or added. Default lock type. Pessimistic adLockPessimistic Records are locked as soon as editing begins. Optimistic adLockOptimistic Locks row only when update is called. Used when having multiple users making changes to the same records is not a major concern. Batch optimistic adLockBatchOptimistic Outside course scope

Syntax for Opening Record Sets Open a Scrollable, updatable Recordset with parameters sql = “Select * from students” Rs.open sql, conn, adOpenStatic, adLockOptimistic, adCmdText Open a RecordSet after setting the properties Set rs = Server.CreateObject("ADODB.RecordSet") rs.LockType = adLockOptimistic rs.CursorType = adOpenStatic rs.Open sql, conn * adCmdText – indicates that the source holds command text, such as an SQL command

Adding Records If you call RS.AddNew It will create a new, blank record and make it the current record You can then assign values to the fields Finally, call RS.Update to write the changes to the DB

Adding Records RS.AddNew RS(“firstName”) = “Fred” RS(“lastName”) = “Flintstone” RS.Update

Updating Records To update an existing record Get the record from the database Modify the field(s) Call Update or CancelUpdate RS(“firstName”) = “Frederick” RS.Update

Deleting Records You can delete an existing record by Find the record you want to delete (sql query) Call RS.Delete RS.MoveFirst RS.Delete