This example describes a method for connecting an Access database using Adodb.connection, and the driver type version is: Microsoft.Jet.OLEDB.4.0. In VB database operation, the connection database is the first step, is also the most basic, this example in this article, for beginners to learn how to connect Access database in VB has a good reference value.
The specific implementation code is as follows:
VERSION 5.00
Begin VB. Form Operation Database
Caption = "VB operation Database"
clientheight = 3645
clientleft = 4905
ClientTop = 4260
clientwidth = 5895
linktopic = "Form1"
ScaleHeight = 3645
scalewidth = 5895
end
Attribute vb_name = "Operation Database"
Attribute Vb_globalnamespace = False
attribute vb_creatable = False
attribute Vb_predeclaredid = True
Attribute vb_exposed = False
Option Explicit
Private Sub form_load ()
Dim database as Object
Set database = New A Dodb. Connection Call
database. Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb;") ' Connect to the database
If (database. state) = (adStateOpen)) Then
MsgBox ("Successful connection!")
Else
MsgBox ("Connection Failed!"). ") End
If
database. Close
Set database = Nothing End
Sub
This instance creates a new ADODB named "Database." Connection object, with this object to increase the database, after the successful connection, pop-up message box to tell the connection results, in most cases, VB and Access2003 Previous version of the database connection, basically all this. Test the database in the VB Peer directory, Data.mdb can be modified according to their actual database path.