vba把excel导入mysql_VBA将Excel数据表格直接导入SQL Server数据库

[vb]代码库'把当前Excel工作簿的所有工作表的数据表格转换为Insert语句并导入SQL Server数据库中。

Option Explicit

Public Sub CreateAllSheetsInsertScript()

On Error GoTo ErrorHandler 'recordset and connection variables

Dim Row As Long

Dim Col As Integer

'To store all the columns available in the all of the worksheets

Dim ColNames(100) As String

Dim ColCount As Integer

Dim MaxRow As Long

Dim CellColCount As Integer

Dim StringStore As String 'Temporary variable to store partial statement

Dim InsertScriptHead As String

Dim DBname As String

Dim TableName As String

Dim Ret As Long

Dim Cnxn As New ADODB.Connection

DBname = "DB1"

TableName = "Table1"

Cnxn.Open "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=" & DBname & ";Integrated Security=SSP

你可能感兴趣的:(vba把excel导入mysql_VBA将Excel数据表格直接导入SQL Server数据库)