Visual Basic ADO Programming 56:150 Information System Design.

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.
Different type of input Use of Basic language with Excel Silvia Patacchini.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
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
Using Objects and Properties
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
Programming the RecordSet Object
Using ADO Programmatically The Connection Object and the Command Object.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
Visual Basic Database Access BICS546. Microsoft Universal Data Access OLE DB: The OLE database protocol –Allows a program to access information in any.
Database Programming (using ADO) Universal Data Access – Microsoft strategy for providing access to information across the enterprise. – UDA provides high-performance.
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.
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.
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”
Overview of Database Access in.Net Josh Bowen CIS 764-FS2008.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
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.
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.
Using the Select Case Statement and the MsgBox Function (Unit 8)
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Using Visual Basic 6.0 to Create Web-Based Database Applications
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 11 Accessing Database.
Copyright © 2001 by Wiley. All rights reserved. Chapter 9: Introduction to Working with Databases in Visual Basic Database Concepts Relational Database.
Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10.
ADO 2.5 Kamaljit Bath, Program Manager Data Access Group.
Universal Data Access and OLE DB. Customer Requirements for Data Access Technologies High-Performance access to data Reliability Vendor Commitment Broad.
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.
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.
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.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
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.
5-1 VISUAL J++ Colorado Technical University IT420 Tim Peterson.
HNDIT Rapid Application Development
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,
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 & 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.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
 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.
INT213 Updating the Database.
ربط الفيجوال بيسك VB مع قواعد البيانات
VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY.
Chapter 10 ASP and Data Store Access
Excel Import data from Access to Excel (ADO) using VBA
Presentation transcript:

Visual Basic ADO Programming 56:150 Information System Design

Introduction 1 Microsoft ActiveX Data Objects (ADO) enables you to write an application to access and manipulate data in a database server through an OLE DB data provider. High speed, ease of use, low memory overhead, and a small disk footprint

Introduction 2 What’s data provider A control or object that provides data for use with another control or program. The data provider makes data connectivity much easier by hiding most of the implementation of data storage. What’s OLE DB A set of COM-based interfaces provide applications with uniform access to data stored in diverse information sources, or data stores

Introduction 3 To use ADO objects in an application, you must first add a reference to the ADO component. Start a Standard EXE project and then select Project  References. In the Reference window, locate Microsoft ActiveX Data Objects 2.x Library and check the box before it.

Main Objects The ADO object model defines a collection of programmable objects that can be used by any of the Microsoft Visual languages

The Connection Object to establish connections between the client and database server ConnectionString Property a long string with several attributes separated by semicolons “Provider = Microsoft.Jet.OLEDB.4.0; Data Source=C:\Program Files\VB98\Nwind.mdb” “Provider=SQLOLEDB.1;User ID=sa; password=; Initial Catalog=Northwind; Data Source=EXPERTNEW”

The Connection Object Open Method CN.open The open method accepts a number of optional arguments (ConnString, UserID, password, options) Close Method CN.Close Set CN = Nothing (remove the Connection Object from memory)

Connection Example Dim dbcon as ADODB.Connection Set dbcon = New ADODB.Connection dbcon.ConnectionString _ ="Provider=MSDASQL.1;Persist Security _ Info=False;Data Source=NWIND" dbcon.ConnectionTimeout = 10 dbcon.Open dbcon.close Set dbcon = Nothing

The Command Object to issue commands, such as SQL queries and updates, to the database ActiveConnection Property If ActiveConnection is set with a reference to a Connection Object, the Command object uses an exiting connection. If ActiveConnection is set with a connection string, a new connection is established.

The Command Object Execute Method Use the Execute method of the Command object to execute a query, data definition command, or stored procedure. Set rs = cmd.Execute(NumRecords, Parameters, Options) Options specify the type of query (in the form of CommandTypeEnum constant) to optimize processing.

CommandTypeEnum adCmdStoreProc The command is the name of a Stored procedure adCmdTable The command is a table’s name. “Select * from table_name” is passed to the server adCmdTableDirect The command is a table’s name. More efficient that adCmdTable option adCmdText The command is a SQL statement adCmdUnknown The command is unknown (default)

Command Example Dim cmd As ADODB.Command Dim rst As ADODB.Recordset Set cmd = New ADODB.Command cmd.CommandText = "select distinct ShipCountry from orders" cmd.CommandType = adCmdText Set cmd.ActiveConnection = dbcon Set rst = New ADODB.Recordset Set rst = cmd.Execute

Command Example You can do delete, update, insert using Command Object with the right sql sentence. Dim cmd As ADODB.Command Dim lngAffected As Integer Set cmd = New ADODB.Command cmd.ActiveConnection = dbcon cmd.CommandType = adCmdText cmd.CommandText = "UPDATE tblOrders SET ShipCountry = 'United States' WHERE ShipCountry = 'USA'“ cmd.Execute lngAffected

The Recordset Object to view and manipulate the results of the query Open Method To execute a query open ( [Source], [ActiveConnection], [CursorType As CursorTypeEnum = adOpenUnspecified], [LockType As LockTypeEnum = adLockUnspecified], [Options As Long = -1])) Source can be a sql statement, a valid command object, a table name, a query name (Access), a stored procedure name (SQL Server) Options is a constant that indicates how the provider should evaluate the Source argument if it represents something other than a Command object

Cursor Type (CursorTypeEnum) adOpenForwardOnlyThis cursor can be scanned forward only, is suitable for one-pass operations. Less expensive than other types of cursors (default) adOpenStatic A snapshot of the database the moment the cursor was created. It can be scanned in both directions. You can’t see modifications made by other users after the creation of the cursor. adOpenKeyset Like a dynamic cursor, except that you can't see records that other users add. Data changes by other users are still visible. adOpenDynamic Additions, changes, and deletions by other users are visible, and all types of movement through the Recordset are allowed.

The Recordset Object Example Dim rst As ADODB.Recordset Dim StrSQL As String Set rst = New ADODB.Recordset StrSQL = "select Description from categories where categoryname = '" & Combocategory.Text & "'" rst.Open Source:=StrSQL, ActiveConnection:=dbcon, Options:=adCmdText

The Recordset Object AddNew: add new rows to recordset rst.AddNew rst.Fields("LastName") = "Smith" rsr.Fields("FirstName") = "Tommy" rst.Update Use the update method to save the new row. If you attempt to close the recordset with an update pending but haven't explicitly saved the row, you'll get a runtime error

The Record Object Change data Move to the desired row Make changes optionally use update method to save updates rst.Find "[ContactTitle] = 'Owner'" If rst.EOF Then MsgBox "No Match was Found!" Else rst.Fields("ContactTitle") = "Manager" rst.Update

The Recordset Object Delete records Find the desired rows Use delete method to delete. rst.Find "[ContactTitle] = 'Owner'" If rst.EOF Then MsgBox "No Match was Found!" Else rst.delete End if

The Recordset Object Other frequently used methods Cancelupdate, Movefirst, Movenext, Movelast, Moveprevious Other frequently used Properties Fields, Filter, RecordCount

ADO Data Control Nothing new but a wrapper for the ADO Recordset object. Unlike the Recordset object, ADODC is visible at run time. It will be shown in Sample program.