Accessing Database Information Using Visual Basic:



Similar documents
Visual Basic Database Programming

Database Applications with VDBT Components

Commercial Database Software Development- A review.

Chapter 4 Accessing Data

Use the ADO Control in your Visual Basic 6 projects

CHAPTER 1: CLIENT/SERVER INTEGRATED DEVELOPMENT ENVIRONMENT (C/SIDE)

Siemens Applied Automation Page 1 11/26/03 9:57 PM. Maxum ODBC 3.11

Producing Listings and Reports Using SAS and Crystal Reports Krishna (Balakrishna) Dandamudi, PharmaNet - SPS, Kennett Square, PA

Multi-user Databases with Microsoft Access

Accessing Your Database with JMP 10 JMP Discovery Conference 2012 Brian Corcoran SAS Institute

Proficy* HMI/SCADA - ifix U SING SQL

Classes para Manipulação de BDs 5

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

ACDS AIMS Certified Database Specialist Course.

Setting Up ALERE with Client/Server Data

Getting Started with STATISTICA Enterprise Programming

Introduction to Databases

INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO:

Chapter 7 -- Adding Database Support

I/A Series Information Suite AIM*DataLink

Saskatoon Business College Corporate Training Centre

Intro to evis: the event visualization tool

Hands-On Lab. Building a Data-Driven Master/Detail Business Form using Visual Studio Lab version: Last updated: 12/10/2010.

Linking Access to SQL Server

Introduction to Visual Basic

SQL Server An Overview

Access 2000 and Visual Basic 6

Inmagic ODBC Driver 8.00 Installation and Upgrade Notes

Chapter 2 Database System Concepts and Architecture

Benchmarks of SQL Query Performance for ODBC and Oracle Call Interface

Course 20461C: Querying Microsoft SQL Server Duration: 35 hours

Integrating Web & DBMS

LabVIEW Report Generation Toolkit for Microsoft Office User Guide

Demystified CONTENTS Acknowledgments xvii Introduction xix CHAPTER 1 Database Fundamentals CHAPTER 2 Exploring Relational Database Components

Introduction to Microsoft Access 2003

Release 2.1 of SAS Add-In for Microsoft Office Bringing Microsoft PowerPoint into the Mix ABSTRACT INTRODUCTION Data Access

Troubleshooting guide for errors in Active Server Pages and Microsoft Data Access Components

FileMaker 11. ODBC and JDBC Guide

Visual COBOL ASP.NET Shopping Cart Demonstration

Creating a Participants Mailing and/or Contact List:

Security Development Tool for Microsoft Dynamics AX 2012 WHITEPAPER

ODBC Client Driver Help Kepware, Inc.

Modifier with Visual Basic with Applications (VBA) in Microsoft Dynamics GP 9.0

MONAHRQ Installation Permissions Guide. Version 2.0.4

Using SQL Server Management Studio

Visual Basic. murach's TRAINING & REFERENCE

FileMaker 13. ODBC and JDBC Guide

User Manual. Crystal Report Integration

Implementing and Maintaining Microsoft SQL Server 2008 Integration Services

Advantage Database Server

for Networks Installation Guide for the application on the server August 2014 (GUIDE 2) Lucid Exact Version 1.7-N and later

FileMaker 12. ODBC and JDBC Guide

for Networks Installation Guide for the application on the server July 2014 (GUIDE 2) Lucid Rapid Version 6.05-N and later

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

EMPLOYEE TRAINING MANAGER USER MANUAL

Tutorial 3 Maintaining and Querying a Database

How to Use PIPS Access to/from SQL Database Utility Program. By PIPSUS Support Team Dr. Chouikha

2012 Teklynx Newco SAS, All rights reserved.

PUBLIC. How to Use in SAP Business One. Solutions from SAP. SAP Business One 2005 A SP01

Advantage Database Server or Microsoft SQL Server which one is right for you?

A database is a collection of data organised in a manner that allows access, retrieval, and use of that data.

No Stress Tech Guide To Crystal Reports XI: For Beginners. By Dr. Indera E. Murphy

IENG2004 Industrial Database and Systems Design. Microsoft Access I. What is Microsoft Access? Architecture of Microsoft Access

Installing Cobra 4.7

Access Tutorial 3 Maintaining and Querying a Database. Microsoft Office 2013 Enhanced

Course ID#: W 35 Hrs. Course Content

COMMON All Day Lab 10/16/2007 Hands on VB.net and ASP.Net for iseries Developers

CRM Setup Factory Installer V 3.0 Developers Guide

Teradata SQL Assistant Version 13.0 (.Net) Enhancements and Differences. Mike Dempsey

Querying Microsoft SQL Server 20461C; 5 days

ASP.NET Programming with C# and SQL Server

UQC103S1 UFCE Systems Development. uqc103s/ufce PHP-mySQL 1

Module 1: Getting Started with Databases and Transact-SQL in SQL Server 2008

Release Notes For Versant/ODBC On Windows. Release

How To Understand The Error Codes On A Crystal Reports Print Engine

ODBC Overview and Information

ODBC Sample Application for Tandem NonStop SQL/MX

Special Edition for FastTrack Software

Excel Companion. (Profit Embedded PHD) User's Guide

for Networks Installation Guide for the application on a server September 2015 (GUIDE 2) Memory Booster version 1.3-N and later

Choosing a Development Tool

SQL Direct User Guide

Introduction to Visual FoxPro

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL

Querying Microsoft SQL Server Course M Day(s) 30:00 Hours

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Micro Focus Database Connectors

Oracle 10g PL/SQL Training

INTEGRATING MICROSOFT DYNAMICS CRM WITH SIMEGO DS3

Querying Microsoft SQL Server

Book 3. Database Connectivity. U:\Book\Book_03.doc Database Connectivity

Lab Answer Key for Module 11: Managing Transactions and Locks

MS SQL Express installation and usage with PHMI projects

2. Unzip the file using a program that supports long filenames, such as WinZip. Do not use DOS.

Using Microsoft SQL Server A Brief Help Sheet for CMPT 354

PaperClip Audit System Installation Guide

14 Configuring and Setting Up Document Management

Creating Database Tables in Microsoft SQL Server

Transcription:

Accessing Database Information Using Visual Basic: Data Access Objects and Remote Data Objects Amanda Reynolds Y398--Internship June 23, 1999 Abstract * Data Access Objects * Declaring a Data Bound Control * Connecting a Data Bound Control with a Database * Manipulating Data Records with a Data Bound Control * Remote Data Objects * Description of Remote Data Objects * The Remote Data Object Programming Model * 1 of 11 1/12/12 12:15 PM

Conclusion * Abstract Declaring a Remote Data Object * Connecting a Remote Data Object with a Database * Manipulating Data Records with a Remote Data Object * Much of the programming done today requires data access. With large amounts of data being maintained in databases, access mechanisms that allow manipulation of this data are vital. Visual Basic is a popular programming package because of its user-friendly interface and data access features. Two popular data access mechanisms are data bound controls with data access objects, and remote data controls with remote data objects. The main difference between these methods are that data bound controls are usually used to connect to desktop databases, and remote data objects are used to connect to client/server data (for client database manipulation of a remote database). Data Access Objects Declaring a Data Bound Control A data bound control connects a data control in Visual Basic to a database table or query. Data controls are visual objects that are said to be data-aware. Data controls may include check boxes, images, labels, picture boxes, and text boxes (see figure A). Visual Basic's data controls allow users to access stored database records. The data control establishes a link between the database and other controls in the interface, in a process called binding. When a control is bound, it displays database field contents when the Data control is present. 2 of 11 1/12/12 12:15 PM

Required property settings for the Data control include the DatabaseName property which specifies the complete path to the database (see figure B), and the RecordSource property, which indicates the table to use from the database (see figure C). The DataSource property (specifies the name of the Data control to which it is bound) and the DataField property (specifies the name of a field in the database to which the control is linked) should be set for all form controls that access database information (Cashman, VB 4). Figure A: Components Figure B: Properties table Figure C: Properties Table Connecting a Data Bound Control with a Database The properties list for a data control (see figures B and C) includes a "DatabaseName" to specify the database the control is to connect to and a "Recordsource" to specify the table in the database, or the SQL statement, for the data. SQL stands for Structured Query Language--a high-level language used to manipulate and/or define databases. Data controls rely on Data Access Objects (DAO) to perform processing. The DAO provide a more comprehensive interface to data using Visual Basic--they allow the user to run queries, update database table values and create the structure of databases (McManus, Database Access with Visual Basic 6.0). In general, four parameters must be defined for data access: 1. 2. Database Name--(DatabaseName) This is the full path to the database to which you would like to connect. Table Name--(RecordSource) This is the name of the table in 1) to which you would like to connect. 3 of 11 1/12/12 12:15 PM

3. 4. Field Name--(DataField) This is the field to which your control should be connected. Data Source--(DataSource) This is the name of the data control to be specified in linked components (such as text boxes). This is necessary because it is possible to have two data controls on one form. Manipulating Data Records with a Data Bound Control Users may add records to the database with data controls in two ways: Using the EOFAction property, which indicates the action to take when the user tries to move past the last record in a table. Parameters for the EOFAction property are: 0 for Move Last (move the last record in the database), 1 for EOF (default), or 2 for Add New (adds a new record to the database). Using "AddNew" with the connected data control's record set. (ex. DataCustomer.Recordset.AddNew ) Records may be updated using "Update" with the connected data control's record set in the same way "AddNew" is used. Data binding features may be set for a control in the Procedure Attributes dialog box (see figure D). The Procedure Attributes box is active after a procedure has been added. A procedure may be added to a module by choosing Add Procedure from the Tools menu. After adding the procedure, the full procedure attributes box is available under Tools, Procedure Attributes, then Advanced. The "Name" property must be set to the name of the data control being bound, and the "Property is Data Bound" checkbox must be checked. 4 of 11 1/12/12 12:15 PM

Figure D: Procedure attributes box The checkbox labeled "This property binds to DataField" specifies that the property should appear alone under the DataField Property which is used when a control has a single bound property. The checkbox labeled "Show in DataBindings collection at design time" determines whether the bound property appears in the Properties window under the DataBindings property. The checkbox labeled "Property will call CanPropertyChange before changing" specifies that the control will check with the container to see if the property can be changed (Cashman, VB 4). Remote Data Objects Description of Remote Data Objects Remote Data Objects (RDO) exist as a thin layer over Open Database Connectivity (ODBC)--this technology allows a database client application to connect to a remote database. The application using ODBC does not need to know the specific type of relational database it is connecting to, it simply uses uniform SQL statements to manipulate the data of the remote database (see figure E). RDOs are sets of programmable objects that provide properties, events and methods access to ODBC data (see figure F). The Remote Data Control is similar to the Data Control. It can be dropped on a form and provides a reduced set of properties, events and methods for accessing ODBC data (Mezick, 161). 5 of 11 1/12/12 12:15 PM

Figure E: ODBC Architecture Figure F: Complete Structure of Remote Data Objects The Remote Data Object programming model is similar to the Data Access Objects (DAO) programming model. In RDO, more emphasis is placed on handling stored procedures and their result sets, and less emphasis is placed on data access retrieval methods. Stored procedures are similar to views (stored queries), except that they give you the capability to perform more complex operations on data (McManus, Database Access with Visual Basic 6.0). The following table (figure G) describes each of the objects. The Remote Data Object Programming Model The Remote Data Object programming model is similar to the Data Access Objects (DAO) programming model in many respects. However, far more emphasis is focused on handling stored procedures and their result sets, and less emphasis is placed on data access retrieval methods used solely by ISAM programming models. The following table describes each of the objects 6 of 11 1/12/12 12:15 PM

RDO object Description RdoEngine The base object. Created automatically when you first access RDO in your application. rdoerror Used to handle all ODBC errors and messages generated by RDO. Created automatically. RdoEnvironment Defines a logical set of connections and transaction scope for a particular user name. Contains both open and allocated (but unopened) connections, provides mechanisms for simultaneous transactions, and provides a security context for data manipulation language (DML) operations on the database. rdoenvironments(0) created automatically. RdoConnection Represents an open connection to a remote data source and a specific database on that data source, or an allocated but as yet unconnected object, which can be used to subsequently establish a connection. RdoTable Represents the stored definition of a base table or an SQL view. RdoResultset Represents the rows that result from running a query. RdoColumn Represents a column of data with a common data type and a common set of properties. RdoQuery An SQL query definition that can include zero or more parameters. RdoParameter Represents a parameter associated with an rdoquery object. Query parameters can be input, output, or both. Figure G: RDO Object Model Description Declaring a Remote Data Object To use an RDO, one must first reference the RDO object model using the Reference dialog (see figure H). The Microsoft Remote Data Object 2.0 box should be checked. 7 of 11 1/12/12 12:15 PM

Figure H: References Connecting a Remote Data Object with a Database Next, a variable must be declared as an rdoconnection. The connect string and cursor driver must be included in the connection process. The object must then be instantiated and methods and properties may be called on the connection. Queries may be assigned to recordsets which may be opened with OpenResultSet (see Figure I). 8 of 11 1/12/12 12:15 PM

Figure I: Connecting an RDO and Opening a Query Manipulating Data Records with a Remote Data Object Rows may be added, manipulated, or deleted from an existing record set using AddNew, Edit, Update, and Delete methods. The AddNew method allows you to add an initialized row to a record set that you may edit and apply to the record set and the table (ex. CustRecSet.AddNew adds a new record space to the customer record set which is open for editing). The Edit method allows you to 9 of 11 1/12/12 12:15 PM

open an existing row in your record set for editing (ex. CustRecSet.Edit allows you to edit information in the record that is currently active in the customer record set). After you have entered information into a new row or edited an existing row, you must use the Update method on the record set to commit your work to the appropriate table (ex. CustRecSet.Update saves any changes or additions you have made to the current customer record). If you do not wish to commit the changes you have made, you can use the CancelUpdate method to change the EditMode of the record set to non-editing (see Figure J) (ex. CustRecSet.CancelUpdate erases the buffer holding the additions or changes to the current customer record). The Delete method removes the current row open for editing (ex. CustRecSet.Edit <newline> CustRecSet.Delete removes the current record from the database). EditMode Figure J: Conclusion This paper gives a brief view of the differences of data bound controls and remote data objects. Data bound controls are a fast and simple way to retrieve table information. While remote data control definition is more involved (code must be written to manipulate or add records) than that of data bound controls, RDOs make it easier to retrieve queried information on one or more tables and they are superior to DAOs for client/server applications where a remote database must be accessed. WORKS CITED 10 of 11 1/12/12 12:15 PM

Cashman, Shelly. Microsoft Visual Basic 6. Course Technology, MA, 1999. Mezick, Dan and Hillier, Scot. Visual Basic 5 Certification Exam Guide. McGraw-Hill, NY, 1998. McManus, Jeffrey P. Database Access with Visual Basic 6. Sams, IN, 1999 All screen captures are from MSDN Library Visual Studio 6.0, Subject: RDO 11 of 11 1/12/12 12:15 PM