好吧,您应该能够使用带有匿名参数的 Command 对象来执行此操作,如以下简单的打开例程中所定义:
Public Sub OpenDB()
Set conDB = New ADODB.Connection
conDB.Open strConn
Set cmndUpdate = New ADODB.Command
With cmndUpdate
.Name = "Update"
.CommandType = adCmdText
.CommandText = "UPDATE [PicTable] " _
& "SET [Picture] = ? " _
& "WHERE [ID] = ?"
Set .ActiveConnection = conDB
End With
End Sub
这可以稍后作为 Connection 的动态方法调用,如下所示:
Private Sub cmdReplace_Click()
'We have an open Recordset (RS) to get the ID from. We use the
'current record's ID and update that record with a fixed photo
'file "photo 04.jpg" just for demonstration:
Dim PictureFileName As String
Dim PictureFile As Integer
Dim PictureBlob() As Byte
PictureFile = FreeFile(0)
Open "photos\photo 04.jpg" For Binary Access Read As #PictureFile
ReDim PictureBlob(LOF(PictureFile) - 1)
Get #PictureFile, , PictureBlob
Close #PictureFile
conDB.Update PictureBlob, RS!ID.Value
'Repaint our user interface by calling our ShowData subroutine,
'which displays data from the current record of RS:
ShowData
End Sub
我使用 Jet MDB 进行了快速而肮脏的测试,但我看不出为什么这不适用于旧 6.5 左右的大多数 SQL Server 版本。由于它不使用命名参数,它甚至可以与 SQL Server Compact Edition 一起使用。
有关更完整、可测试的示例,请参阅SQL 参数示例。