excel - ADO 流音乐会转二进制
问题描述
这是我使用 VBA 将文件上传到数据库的代码,但这个循环只能运行一次。在第二个循环中它会给出错误,错误是
在这种情况下不允许操作
有人可以建议我该怎么做吗?错误在行adoStream.Type = adTypeBinary
Dim stCon As String 'SQL Connection string
Dim stProcName As String 'Stored Procedure name
Dim strCmd As String
Dim adoStream As Object
Dim adocmd As Object
Dim strFilePath As String
Dim adoCon As Object
Set adoCon = CreateObject("ADODB.Connection")
Set adoStream = CreateObject("ADODB.Stream")
Set adocmd = CreateObject("ADODB.Command")
adoCon.CursorLocation = adUseClient
adoCon.Open "Provider=SQLOLEDB; " & _
"Data Source=#########; " & _
"Initial Catalog=#######;" & _
"User ID=#######; Password=########;"
For Each fl In fld.Files
If fl.name Like Mask Then
strInput = fl.name
strFilePath = fld.path & "\" & fl.name
MsgBox (strFilePath)
adoStream.Type = adTypeBinary
adoStream.Open
adoStream.LoadFromFile strFilePath 'It fails if file is open
With adocmd
.CommandText = "INSERT INTO dbo.coc_upload(Data) " & _
"VALUES (?)"
.CommandType = adCmdText
'---adding parameters
.Parameters.Append .CreateParameter("@Data", adVarBinary, adParamInput, adoStream.Size, adoStream.Read)
'---
End With
adocmd.ActiveConnection = adoCon
adocmd.Execute
adoCon.Close
MsgBox ("Done")
End If
Next
解决方案
推荐阅读
- cmake - 如何通过使用特殊参数调用 cmake 来更改 CMakeLists.txt 中的选项
- jitsi - JITSI 视频会议 - 当主持人/主持人离开会议时,是否有任何配置或 API 可以踢出所有参与者?
- php - Domdocument:为什么 XSLT 转换输出变成单行?
- arm - gem5 完整系统 Linux 启动失败并显示“内核恐慌 - 未同步:VFS:无法挂载根 fs”
- html - 如何将此菜单分成两列?
- vue.js - 从 Vue 指令中获取目标元素
- amazon-web-services - 如何检查 dynamoDB 表被访问的次数
- javascript - 我无法启用 google my business api
- c# - Asp.Net MVC 路由概念
- java - 在 Java Spring boot 中理解映射的问题