VB6 implements the ADODB code implementation method that connects an Access database _vb

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.