您好,我正在尝试将 excel 表中的值复制到同一数据库中的新表中Select * INTO query
。
提取到 excel 的数据来自其他表,在编辑 excel 中的某些列后,我需要将 excel 表发送回 SQL 数据库并创建新表。
我的代码有问题,上面写着错误:
Run- time error '-2147217900 ' Automation Error
我正在使用VBA 宏将表值从 Excel导入和导出到SQL 。
这是我的代码
Dim adoCN As ADODB.Connection
Dim sConnString As String
Dim sSQL As String
Dim lRow As Long, lCol As Long
sConnString = "Provider=sqloledb;Server=;Database=mycon;User Id=;Password="
Set adoCN = CreateObject("ADODB.Connection")
adoCN.Open sConnString
'Assumes that you have Field1, Field2 and Field3 in columns A, B and C
'For this example we can assume that the data exists on Sheet1, with a header on row
'1 and data in rows 2-11
'Also assume that the fields are defined as character (e.g. varchar or char)
'Text values must be enclosed in apostrophes whereas numeric values should not.
'adoCN.Open
For lRow = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
sSQL = "SELECT * INTO TestTable FROM Sheets(1)$"
***adoCN.Execute sSQL***
Next lRow
adoCN.Close
Set adoCN = Nothing
'On Error GoTo 0
行错误:adoCN.Execute sSQL
请帮帮我。