The example in this article describes how to use ADODB.Connection to connect to the access database. The driver type version is: Microsoft.Jet.OLEDB.4.0. In the database operation of VB, connecting to the database is the first step and the most basic. The example described in this article has a good reference value for beginners to learn how to connect to the Access database in VB.
The specific implementation code is as follows:
VERSION 5.00Begin VB.Form Operation Database Caption = "VB Operation Database" ClientHeight = 3645 ClientLeft = 4905 ClientTop = 4260 ClientWidth = 5895 LinkTopic = "Form1" ScaleHeight = 3645 ScaleWidth = 5895EndAttribute VB_Name = "Operation Database" Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption ExplicitPrivate Sub Form_Load()Dim Database As ObjectSet Database = New ADODB.ConnectionCall Database.Open("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=Data.mdb;") ' Connect to databaseIf ((database.State) = (adStateOpen)) Then MsgBox ("Connection successful!")Else MsgBox ("Connection failed!")End If database.CloseSet database = NothingEnd SubThis example creates a New ADODB.Connection object named "database". Use this object to connect to the database. After the connection is successful, a message box pops up to inform you of the connection result. In most cases, VB and databases before Access2003 Connections are basically like this. Please place the test database in the same directory as VB. Data.mdb can be modified according to your actual database path.