Connection between vb and access Database in. accdb format

Source: Internet
Author: User
When you use vb to connect to the access database, the following error occurs: Your database is not recognized by the program. The default value of vb is., which is the database type of mdbaccess! At this time, let's take a look at what we want to connect to the. accdb type. Let's take a look at the code. We used ProviderMicrosoft. jet. oledb.4.0 as a database.

When you use vb to connect to the access database, the following error occurs: Your database is not recognized by the program. The default value of vb is., mdb access Database! At this time, let's take a look at what we want to connect to the. accdb type. Let's take a look at the code. We used Provider = Microsoft. jet. oledb.4.0 as a database.

In vbConnectionAccessDatabaseThe following error occurs:

This is yoursDatabaseThe format is not recognized by the program. The default value of vb is., mdb accessDatabaseFormat! Now let's take a look at what we wantConnectionOf

Yes. accdb format.

Let's take a look at the code. We used:

Provider = Microsoft. jet. oledb.4.0

WhenDatabaseWhen the format changes,ConnectionSyntax format changed: Microsoft office 12.0 access database engine oledb provider is connected at this time

After the character is created, it becomes the following error.

Why? The reason is that the. accdb data format is not applicable to the jet engine.Connection. Provider = microsoft. ace. oledb.12.0

In this wayConnection.


AccessDatabaseThe format is. mdb, while vb6.0 includesDatabaseThe format is also. mdb, so everyone is used to connecting

Access in. mdb FormatDatabaseBut later than Version 07DatabaseThe format is. accdb.ConnectionIn the process

.

To sum up, generallyConnectionDatabaseWe can use the following twoConnectionMethod:

Add reference and use codeConnection.

The solution is as follows:

I. ReferencesConnection

Add reference and use codeConnection. Project -- reference -- microsoft activeX data objects 2.5 library

In the code window, add:

Dim objcn As NewConnection

Dim objrs As New Recordset

Dim strsql As String

Objcn. ConnectionString = "provider = microsoft. ace. oledb.12.0;" & "data source =" & App. Path & "\ 3. accdb" (3 isDatabase)

Objcn. Open

Strsql = "select password from 3 where account = '" & username & "'" (username is a custom variable in the account table)

Set objrs. ActiveConnection = objcn

Objrs. Open (strsql)

Ii. ControlsConnection:

1. Project -- component -- add the microsoft ado data control 6.0 control.

2. attribute settings:

Click Generate to openConnectionString, select, microsoft office 12.0 access database engine ole db provider

3. SetConnectionPath.


ThenConnectionEnter your optionDatabasePath. TestConnection, IfConnectionSuccessful, it indicatesDatabaseBound to your vbprogram.


4. Set the record source:



In this way, your access over 2007DatabaseYou canConnectionVbprogram.

The premise of all this is that you will use officeaccess to establishDatabaseAnd is correctDatabaseOh!

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.