How to import Access and Excel to the third of MySQL

Source: Internet
Author: User
Tags mysql mysql database
Access|excel|mysql two. VB Program of Guide Library

This project to use some object library, in the database access, decided to use ADO (ActiveX Data Objects), for the use of ASP, the name should be very familiar with, in fact, it in the application of VB is almost the same, because to operate Excel, Also refer to an Extended object library. Click "Project"---"References" in the Point menu, select "Microsoft ActiveX Data Objects 2.6 Library" and "Microsoft Excel 9.0 Object Library", in the list of references, The version of the referenced object library may be different, so choose the latest version of the same. To use dialog boxes and progress bars, and to refer to some parts, "engineering" in a la carte--"parts", select "Microsoft Common Dialog Control 6.0 (SP3)" and "Microsoft Windows Common Controls 6.0 (SP3) ".

The interface is shown in Figure one

The controls represented by the numbers in the figure are:

1-3:3 are TextBox controls, with the name mdbfilename,mdbpassword,xlsfilename,mdbfilename used to indicate the path and file name of the import Access file. Mdbpassword The password used to enter the Access file, Xlsfilename to indicate the path and filename of the import Excel file;

4: The name is Select_mdbfile,commandbutton control, used to select the Access file to import;

5: Name is Importmdb,commandbutton control, after selecting good file, use this button to import MDB file

6: Name is Commondialog1,commondialog control

7: The name is Select_xlsfile,commandbutton control, used to select the Excel file to import;

8: The name is Importxls,commandbutton control, select Good file, use this button to import XLS file;

9: Name is Commondialog2,commondialog control

10: Name is PrgBar1, progress bar (ProgressBar), when you want to import many records, use the progress bar to indicate the current import progress

11: The name is StatusBar1, status bar (StatusBar), indicating the progress status of the import, including "Import", "import complete" and so on.

To set the style to "1-sbrsimple"


Make the following statement on the head of the program

Option Explicit

Dim Cn as New ADODB. Connection

Dim Cnmysql as New ADODB. Connection

Dim Rs as New ADODB. Recordset

Dim Rsmysql as New ADODB. Recordset


Function Replace_str (srcstr as String)

Srcstr = Replace (srcstr, "\", "\ \")

Replace_str = Replace (Srcstr, "'", "\")

End Function



Double-click the form to enter the following code when the form is loaded

Private Sub Form_Load ()

' Set the progress bar to invisible

Prgbar1.visible = False

' Connect MySQL database, pwd for database password, UID is username, DSN is the name of data source

cnmysql.connectionstring = "uid=root;pwd=;d sn=build"

Cnmysql.open

End Sub



Related Article

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.