那麼你應該能夠這樣使用匿名參數的命令對象的事,因爲在這個簡單的打開例行程序定義:
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