sql-server - 使用宏的 Excel (MAC) 到 SQL Server 连接
问题描述
我在 MAC 中有一个启用宏的 Excel 表,其中有一些数据并希望将其导出到 SQL Server。我试图先截断目标表然后插入,但我的代码不起作用。该代码需要在 MAC 和 Windows 上运行。请帮忙。
Sub Export_Click()
Dim sqlstring As String
Dim connstring As String
Dim sLogin As String
Dim rng As Range
Dim defaultDate As String
Dim sql As String, bulkSql As String
Dim intImportRow As Integer
Dim Product, Resource As String
Dim name, address as String
'sLogin = "Uid=$;Pwd=$;"
'sqlstringfirma = "SELECT * from tableA"
connstring = "ODBC;DRIVER=SQL Server;SERVER=ServerIP;DATABASE=databse;UID=uid;PWD=pwd"
sql_trunc = "truncate table tableA"
sql_commit = "commit"
sql_query = "select * from table tableA"
With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A1"), sql:=sql_trunc)
.BackgroundQuery = False
'.Refresh
End With
intImportRow = 10
Do Until .Cells(intImportRow, 1) = ""
Product = .Cells(intImportRow, 1)
Resource = .Cells(intImportRow, 2)
sql_insert = "insert into tableA (name, address) values ('" & name & "', '" & address & "')"
With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A1"),
sql:=sql_insert)
.BackgroundQuery = False
.Refr
intImportRow = intImportRow + 1
Loop
End Sub
解决方案
推荐阅读
- angular - 通过 nativeElemet 动态添加弹出框(ngx bootstrap)
- ibm-cloud - Cloud Functions REST API:从 zip 文件创建新操作
- r - 粘贴两个字符列表矩阵
- c# - 当其他属性为“真”时,指示 ReSharper 字段不为空
- mysql - MYSQL:将自动增量值插入几列
- python - IndexError:列表索引超出python动态可变长度的范围
- javascript - Javascript如何使用包装器将节点附加到正确的索引中
- angular - 身份验证拦截器在角度 6 中不起作用
- java - 为什么 .forEach(val -> list.add()) 编译而 .forEach(val -> true) 不编译?
- php - 为什么 store_result() 不返回 num_rows 等效于 mysqli 常规语句?