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!