|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 opiona 于 2024-8-27 21:16 编辑
https://club.excelhome.net/thread-1666858-3-1.html
本质也是用的循环
- Function INSERT_ARRAY_TO_ACCESS(ByVal ARX, ByVal StrNameTable As String, ByVal Str_Coon As String) As Long
- Rem 将数组内数据快速保存到Access数据库
- Rem ARX 数组 含标题
- Rem StrNameTable 数据表名称
- Rem Str_coon 数据库连接字符串
- Rem 北极狐工作室整理 QQ:14885553
- Rem 使用方法:
- Rem ARX = SHD.Range("A1:E" & MAXROW).Value
- Rem StrNameTable = "测试表"
- Rem Str_coon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\database.MDB;Jet OLEDB:Database Password=14885553"
- Rem INTX = INSERT_ARRAY_TO_ACCESS(ARX, StrNameTable, Str_coon)
-
-
- Dim CN, RS
- Dim I, X, INTX, ICOL, LB As Long
-
- Set CN = CreateObject("Adodb.Connection") '//新建一个ADO连接
- Set RS = CreateObject("adodb.recordset")
- CN.Open Str_Coon
-
- CN.BeginTrans
- RS.LockType = adLockPessimistic
- RS.Open StrNameTable, CN
-
- INTX = 0
- LB = LBound(ARX, 1)
- For I = LB + 1 To UBound(ARX, 1)
- RS.AddNew
- Rem RS("日期") = SHX.Cells(I, 1).Value;RS("订单号") = SHX.Cells(I, 2).Value;RS("数量") = SHX.Cells(I, 3).Value
- Rem 日期 订单号 数量
- For ICOL = LB To UBound(ARX, 2)
- RS(ARX(LB, ICOL)) = ARX(I, ICOL)
- Next
- RS.Update
- INTX = INTX + 1
- Next
- CN.CommitTrans
- RS.Close
- CN.Close
- INSERT_ARRAY_TO_ACCESS = INTX
- End Function
复制代码
|
|