Programming the RecordSet Object

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.
1 Chapter 10 Protecting Data Integrity in a Multiuser Environment.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Persistent data storage: relational databases and ADO.
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 ADO Programmatically The Connection Object, Command Object, and Recordset Object.
CVEV 118/698 Database Programming Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.
Using Objects and Properties
ActiveX Data Control BICS 546. Intrinsic and ActiveX Controls VB supports two types of controls: –Intrinsic controls (command button, listbox, etc): When.
Web-based Programming Lanjut Pertemuan 6 Matakuliah: M0492 / Web-based Programming Lanjut Tahun: 2007.
 2004 Tau Yenny, SI - Binus M0194 Web-based Programming Lanjut Session 6.
Using ADO Programmatically The Connection Object and the Command Object.
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.
Adding, Updating, and Deleting Records from a Recordset.
CIS 451: ASP Recordsets Dr. Ralph D. Westfall May, 2002.
1 Chapter 8 Object-Based Programming in VBA. 8 Chapter Objectives Declare and use object variables Create procedures that use built-in form methods Find.
Component 8, Slide 1 CP2030 Visual basic for C++ Programmers, ‘The VB Team’ Copyright © University of Wolverhampton CP2030 Visual Basic For C++ Programmers.
ASP & ADO. Connection Object An implicit connection is created when we open a recordset without a connection object. –rs.open “Customer”, "DSN = Sales”
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.
CSE2207/CSE3007 Rapid Applications Programming for Windows Week 6.
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.
Handling of data from multiple databases. Visual Basic Database Visual Basic application acts as a front-end to the database Visual Basic application.
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.
Working with Numeric Variables (Unit 6) Visual Basic for Applications.
Numeric Variables Visual Basic for Applications 6.
Copyright © 2001 by Wiley. All rights reserved. Chapter 9: Introduction to Working with Databases in Visual Basic Database Concepts Relational Database.
ADO 2.5 Kamaljit Bath, Program Manager Data Access Group.
Faculty of Electronic Engineering 1 Database Access API’s Aleksandar Stanimirović Leonid Stoimenov Aleksandar Milosavljević.
EM412 Using Adaptive Server Anywhere with Visual Basic Ali Chalhoub Technical Support Consultant iAnywhere Solutions
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.
New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B.
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.
Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information.
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.
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.
What’s new in ADO 2.5 Greg Hinkel Program Manager Data Access Group
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.
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 and DataList, DataCombo and DataGrid Controls Please use speaker notes for additional information!
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.
Generating XML Data from a Database Eugenia Fernandez IUPUI.
 2 Data Object Library approaches ◦ DAO (Data Access Objects)  Original access strategy (up to VB6)  Closely linked to MS Access ◦ ADO (ActiveX Data.
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
ActiveX Data Objects (ADO)
The Recordset Object.
INT213 Updating the Database.
ربط الفيجوال بيسك VB مع قواعد البيانات
Please use speaker notes for additional information!
MICROSOFT VISUAL BASIC
Chapter 10 ASP and Data Store Access
Database Objects 1/12/2019 See scm-intranet.
Working With Databases
Excel Import data from Access to Excel (ADO) using VBA
Presentation transcript:

Programming the RecordSet Object

Recordset Object (ADO) When you use ADO, you manipulate data almost entirely using Recordset objects. A Recordset object represents the entire set of records from a database table or the results of an executed command. All Recordset objects are constructed using records (rows) and fields (columns).

Cursor A cursor caches data on a client. Provides synchronization mechanisms Provides tools to minimize network traffic. Define how a cursor is created using the CursorLocation and CursorType properties pertaining to the Recordset object. You must set these properties before opening the recordset. cursor In database technology, a piece of software that returns rows of data to the requesting application. A cursor keeps track of the position in the result set, and multiple operations can be performed row by row against a result set with or without returning to the original table. In other words, cursors conceptually return a result set based on tables within the databases. The cursor is so named because it indicates the current position in the result set, just as the cursor on a computer screen indicates current position.

The Recordset CursorLocation Property Specifies the location of the cursor engine and can be set to one of two constants: adUseClient adUseServer default If set to adUseClient, the program uses a local client cursor. Local client cursors tend to support additional functionality beyond that supported by server cursors. If set to adUseServer (the default), the program uses the cursor supplied with the data provider.

The Recordset CursorType Property The CursorType property defines the kind of cursor that will be opened. adOpenStatic creates a static cursor adOpenForwardOnly creates a forward only cursor adOpenDynamic creates a dynamic cursor adOpenKeyset creates a keyset cursor The constant value adOpenStatic creates a static cursor. A static copy of the data is created and stored in the Recordset object. Changes made to this static copy do not become visible to other users. The constant value adOpenForwardOnly creates a cursor that is identical to a static cursor, but can only scroll forward through the records. In situations when you need to scroll through a group of records only once to print a report or perform a similar task, forward-only cursors represent the optimal choice because they improve performance. The constant value adOpenDynamic creates a dynamic cursor. Additions, changes, and deletions will then be valid and visible to other users. The constant value adOpenKeyset creates a keyset cursor. A keyset cursor is identical to a dynamic cursor, but records added by other users are not reflected in the open recordset. If a user deletes a record, that record is not accessible in your recordset. Changes to existing records made by other users are visible to your recordset.

The Recordset LockType Property To resolve the conflicts that may arise when two users try to change the same records, database providers support locking. To specify the type of locking, set the LockType property to one of the following: adLockReadOnly (default) adLockPessimistic adLockOptimistic In multi-user environments, more than one user may access the same database simultaneously. Furthermore, multiple users may attempt to edit the same record or group of records at the same time. If the LockType property is set to adLockReadOnly, the provider creates a read-only recordset – that is, the contents of the recordset cannot be modified. If the LockType property is set to adLockPessimistic, the provider applies pessimistic locking. With pessimistic locking, a record is locked when editing begins and unlocked after the record is updated. If the LockType property is set to adLockOptimistic, the provider applies optimistic locking. With optimistic locking, the record remains locked only from the time the Update method is called to the time the update finishes.

The Recordset Open Method The Open method opens a cursor (recordset). Syntax: recordset.Open Source recordset must be an instance of an ADO Recordset object. The Source argument is the name of a command object. It can also be an SQL statement or table name.

Private rstCurrent As New ADODB.Recordset Private Sub Form_Load() Dim conMagnet As New ADODB.Connection Dim cmdMagnet As New ADODB.Command conMagnet.Mode = adModeShareDenyNone conMagnet.Provider = "Microsoft.Jet.OLEDB.4.0" conMagnet.ConnectionString = "Data Source=A:\Magnet.mdb" conMagnet.Open Set cmdMagnet.ActiveConnection = conMagnet cmdMagnet.CommandType = adCmdTable cmdMagnet.CommandText = "tblOrderMaster" rstCurrent.LockType = adLockOptimistic rstCurrent.CursorLocation = adUseClient rstCurrent.CursorType = adOpenKeyset rstCurrent.Open cmdMagnet Call LoadCurrentRecord End Sub

Recordset Navigation Methods Navigate through the records in a Recordset with the following Recordset methods MoveFirst MoveLast MoveNext MovePrevious Move Examples: rstCurrent.Move +5 rstCurrent.MoveFirst rstCurrent.MoveLast MoveFirst and MoveLast methods move to the first and last records in the recordset. The MoveNext and MovePrevious methods move relative to the current record or bookmark. The Move method moves a specific number of rows forward or back. The examples show navigation statements to move through a Recordset object named rsCurrent

Recordset BOF and EOF Properties The BOF and EOF properties indicate the beginning or end of the Recordset. The BOF or EOF property is True when you move one record past the first or last record. If both BOF and EOF are True, there are no records in the Recordset. Example: If rstCurrent.BOF = True Then rstCurrent.MoveFirst EndIf When you open a Recordset, the current record is positioned to the first record (if any) and the BOF and EOF properties are set to False. When you use MoveNext or MovePrevious, you should check the BOF and EOF properties to make sure you do not move off the recordset. The example checks for the beginning of a Recordset object named rsCurrent.

Recordset RecordCount Property Use the RecordCount property to return the number of records in a Recordset object. The property returns -1 when ADO cannot determine the number of records. Reading the RecordCount property on a closed Recordset causes an error. Example: txtRecordCount.Text = rstCurrent.RecordCount

Recordset AbsolutePosition Property Use the AbsolutePosition property to determine the current record number The AbsolutePosition property is a Long Integer between 1 and the number of records in the Recordset. Example: Use the AbsolutePosition property to move to a record based on its ordinal position in the Recordset object, or to determine the ordinal position of the current record. txtCurrentRecord.Text = rstCurrent.AbsolutePosition

Recordset Find Method recordsetName.Find (criteria) Searches a Recordset for the record that satisfies the specified criteria. If the criteria is met, the recordset position is set on the found record; otherwise, the position is set on the end of the recordset. Example: rstCurrent.Find “[Member ID] = 1234” Parameters criteria   A String containing a statement that specifies the column name, comparison operator, and value to use in the search.

Examples Dim strName As String strName = "John Smith" rstCurrent.Find "fldID = 123" rstCurrent.Find "fldName = 'John Smith'" rstCurrent.Find "fldName = '" & strName & "'"

Private Sub cboMemberID_Click() Dim strTemp As String strTemp = cboMemberID.Text rstCurrent.MoveFirst rstCurrent.Find "[Member ID] = '" & strTemp & "'" Call LoadCurrentRecord End Sub In this example, LoadCurrentRecord is a general sub procedure that fills the form text fields with information from the recordset.