Sunteți pe pagina 1din 4

Using the ADO Library

To use the ADO Library inside a Visual Basic 5.0 project,follow these steps:
1. Install the OLE DB SDK 1.5,which will register all assosciated DLLs and
update all the clients installed on the machine.

2. Go to project from the VB Main toolbar and select project.scroll down until
you get to References and click to bring up the project References dialog box.

3. In the References dialog box, scroll down until you see Microsoft ActiveX
Data Objects 2.0 Library and make sure that the check box is checked.If the
item does not appear in the list you can click the Browse button and try to find
the file yourself.The ADO library DLL is named MSADO15.DLL.

4. Click OK and the ADO library is loaded into the system.

Connection Object Methods and Properties

Some of the parameters to which ADO connects to the database.These properties include
the following:

Command Timeout Sets or returns a Long integer specifying in seconds the


amount of time to wait for a command to execute.If the time exceeds the specified
value.ADO returns an error in the Visual Basic Error object and cancels the
command.

Default Value:30

Connection Timeout Sets or returns a Long integer specifying in seconds the


amount of time before the connection is abandoned.Use this for connections that
involve network routing over a slow or busy network connection.

Default Value:15

Cursor Location sets or returns a Long integer specifying the cursor location.The
constraints for this are adUseClient or adUseServer.This property enables you to
choose between various cursor libraries accessible to the provider.Using
adUseClient that might allow features that driver-side cursors do not provide.Using
adUseServer enables cursors that are sometimes very flexible.
Default Value: adUseServer

Isolation Level sets or returns one of the following IsolationLevelEnum intrinsic


constants:

adXactchaos - you cannot overwrite pending changes from more highly isolated
transcations.

adXactBrowse From one transction you can view uncommitted changes in other
transactions.

adXactCursorStability From one transction you can view changes in other transactions
only after they have been committed.

adXactRepeatableRead From one transction you cannot see changes in other


transactions,but querying again can bring new recordsets.

adXactIsolate Transactions are conducted in isolation from other transactions.

Default Value: adXactCursorStability

Mode Sets or return the access permissions in use by the provider on the
current connection. You can use the Mode only when the State property of the
connection object is closed.

adModeUnknown Indicates that the permissions have not yet been set or cannot
be determined.

AdModeRead Indicates read-only permisssions.


AdModeWrite Indicates Write-only permisssions.
AdModeReadWrite Indicates read/write permisssions.

Default Value: adModeUnknown

Using BeginTrans, CommitTrans, and RollbackTrans

Many database structures that are accessed by more than one individual require the
capability to track changes made to the database and the capability to either accept or
decline those modifications.

The 3 methods that the ADO Connection object incorporates to facilitate these
requirements are:
BeginTrans.
CommitTrans.
RollbackTrans.

Using the Error Object

Each ADO Error object represents a specific provider error,not an ADO error.
By initiating a new request to the Collection object the Error object count is cleared and
then set according to the number of errors returned that were not handled by the ADO
object library.

To get all the errors:

(a) Examine the Errors collection's Count property.

(b) Loop through the object to display all current errors.

The Errors collection holds the numbers and description of the errors that have occured.
This information can br retrieved by using the syntax of the Error_Enumerator code.

The ADO Error object is equivalent to the DAO Workspace's Error object.

Accessing Parameter Queries and Stored Procedures

ADO providers support Parameterized commands.These are the commands where the
desired action is defined once,but variables are used to alter the details of the command.

To handle Parameterized commands,ADO has instituted the Parameter object.

You use the Parameter object collection in conjunction with the ADO command object to
run stored procedures or Parameterized commands.Before using the Parameter
object,examine its following properties and methods:

Attributes Indicates how the Parameter object handles the parameter value.
There are 3 possible options for this property:

adParamSigned Indicates that the accepts assigned values.


adParamNullable Indicates that the parameter accepts NULL values.
adParamLong Indicates that the parameter accepts long binary data.

Default value: adParamSigned

Direction Tells whether the parameter represents an input parameter,an output


parameter,or both,or whether the parameter is the return value from a stored
procedure.There are 4 possible options for this property:
adParamInput Indicates an input parameter.
adParamOutput Indicates an output parameter.
adParamInputOutput Indicates both an input and an output parameter.
adParamReturnValue Indicates an return value.

Default value: adParamInput

Name Assigns or retrives the name of a parameter.For names not yet


appended to the parameters collection,this property is read/write.After the
parameter is added this property is read-only.The Name property of a
parameter is not required to be unique.
NumericScale Determines how many numbers to the right of the decimal
point will be used to represent a value for a numeric parameter.

Precision Indicates the degree of precision to apply to a parameter value.sets


or determines the maximum number of digits used to represent a numeric
value.

Size Used to determine the maximum size for values read or written from
theValue property of the Parameter object.

Type Sets or returns the parameter type as specified in the DataTypeEnum


values collections.
Some of the DataTypeEnum are:

adBigInt An 8- byte signed integer.


adBinary A binary value.
adBoolean A boolean value.
adChar A String value.
adBSTR A null-terminated Unicode character string.

Value Sets or return the value of a parameter.The type of value returned is


predicated by the type set for the specific parameter in the parameters
collection.

S-ar putea să vă placă și