mysql|server| data How to migrate data from Microsoft SQL Server 7.0 to MySQL
Zhbforce
Presumably everyone likes to use Word typing, computing and planning with Excel, PowerPoint slides to show ..., but this only uses a small part of the Office family of products. According to the survey, most users use only 20% of the functionality of Office products, and few people notice visual Basic for application. In fact, familiar with the functions of VBA can make your work more effective, especially for accounting, finance and other professional, make a good macro, can almost make it once and for all! Recently, AutoCAD also added to the function of VBA, which can not but say that this is a trend!
The function of VBA is not only to let the virus manufacturers to create trouble, VBA can be used to create viruses, but also illustrates its powerful and easy-to-use features! The use of ADO object, can be very convenient for database operation! Here is a simple example of a data exchange:
Since the ADO object does not directly support MySQL, you must first install MYODBC, the latter is a free product, download on www.mysql.org, installed MYODBC, you can configure a data source name in ODBC data source management, Point it at the MySQL database you want to connect to. The code is as follows:
Sub Connectmysql ()
' Connect to the MySQL database via MYODBC, and Microsoft SQL Server 7
' Data into MySQL
Dim Sconnect As String, sSQL as String, I as Long
Dim Cnmssql as New ADODB. Connection
Dim Cnmysql as New ADODB. Connection
' Declare and create an object connection
Dim rs as New ADODB. Recordset ' declares and creates an object recordset
Dim cm as New Adodb.command ' declares and creates object commands
Sconnect = "DSN=MYSQL1" Specifies the name of the MySQL data source
Cnmysql.open sconnect ' connect to MySQL
Sconnect= "Provider=SQLOLEDB.1; Persist Security Info=false; User id=sa;pwd=123456;initial catalog=softdown;data Source=ntserver "
' Connect to MS SQL Server 7
Cnmssql.open Sconnect
' sSQL = ' CREATE Table softinfo (softnum smallint,softname varchar (), Softdesc blob, "& _
"Softpath varchar, Softleng varchar (a), Softclass varchar (a), Softsugest tinyint (1)," & _
"Softdown smallint (4))" ' Creates a new MySQL datasheet statement
sSQL = "SELECT * from Softinfo ORDER by Softnum"
Rs. Open sSQL, Cnmssql, 1, 1
While not Rs. Eof
sSQL = "INSERT INTO Softinfo values (" & Trim (RS (0). Value) & ", '" & Trim (RS (1). Value) & _
"', '" & Trim (RS (2). Value) & "', '" & Trim (RS (3). Value) & "', '" & Trim (RS (4). Value) & _
"', '" & Trim (RS (5). Value) & "'," & Trim (RS (6). Value) & "," & Trim (RS (7). Value) & ")"
Cm. ActiveConnection = Cnmysql
Cm.commandtype = adCmdText
Cm.commandtext = sSQL
Cm. Execute
Rs. MoveNext
Wend
Rs. Close
Set rs = Nothing
Cnmysql.close
Set Cnmysql = Nothing
Cnmssql.close
Set Cnmssql = Nothing
End Sub
Well, presumably we have some understanding of VBA, similarly, if you want to reference MySQL in the worksheet data is also the same simple, once the macro has been done, want to generate reports, users want to do is just click the mouse on the line, using Excel for two times development, Efficiency can exceed any user-developed reporting system, as we stand on the shoulders of the Microsoft giant!
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.