那么你应该能够这样使用匿名参数的命令对象的事,因为在这个简单的打开例行程序定义:
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
这可以在以后援引为连接的动态方法,如在:
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
我没有使用喷气MDB一个快速和肮脏的测试,但我看不出为什么这不应该超越老6.5左右大多数的SQL Server版本。由于它不使用命名参数,它甚至应该可以与SQL Server Compact Edition一起使用。
请参阅SQL Parameters Example了解更完整,可测试的示例。
您在添加记录或更新记录时遇到问题?如果是插入,为什么where子句? – rags
我在添加记录时检查用户名时遇到问题。 –
还不清楚。如果你添加没有用户名来检查,那么你的意思是更新而不是添加?是的,我再次问上一个问题。 – Bob77