Sorry to post here as well (in addition to sql subforum) but hoping to see if others have run into this issue...
Here's an approach to uploading an image blob where I try to get away from using Recordsets... but I keep getting errors in the line highlighted towards the bottom. I keep getting truncate right errors, or wrong parameter errors. I've tried all kinds of variations.
Any suggested fixes please?
Here's an approach to uploading an image blob where I try to get away from using Recordsets... but I keep getting errors in the line highlighted towards the bottom. I keep getting truncate right errors, or wrong parameter errors. I've tried all kinds of variations.
Any suggested fixes please?
Code:
Dim sql As String, conn As ADODB.Connection, rst As ADODB.Recordset, mystream As ADODB.Stream
Dim iFileSize As Long, sFullFileName As String, vImage As Variant
Set conn = New ADODB.Connection
conn.ConnectionString = gsADOConnection
conn.CursorLocation = adUseClient
conn.Open
sFullFileName = fnFullFileName(pClient, pPID, pFileID, False)
sql = "DELETE FROM usysServer_tblFileBlobs "
sql = sql + "WHERE Client = '" + pClient + "' AND PID = " + CStr(pPID) + " AND FileID = " + CStr(pFileID)
conn.Execute sql
Set mystream = New ADODB.Stream
mystream.Type = adTypeBinary
mystream.Open
mystream.LoadFromFile sFullFileName
iFileSize = mystream.Size
Dim strQry As String
'sql = "INSERT INTO usysServer_tblFileBlobs (Client, PID, FileID, FileSize) VALUES (?, ?, ?, ?)"
sql = "INSERT INTO usysServer_tblFileBlobs (Client, PID, FileID, FileSize, FileBlob) VALUES (?, ?, ?, ?, ?)"
Dim cm As ADODB.Command
Set cm = New ADODB.Command
cm.ActiveConnection = conn
cm.CommandText = sql
cm.Parameters.Append cm.CreateParameter("@Client", adVarChar, adParamInput, Len(pClient), pClient)
cm.Parameters.Append cm.CreateParameter("@PID", adInteger, adParamInput, , pPID)
cm.Parameters.Append cm.CreateParameter("@FileID", adInteger, adParamInput, , pFileID)
cm.Parameters.Append cm.CreateParameter("@FileSize", adInteger, adParamInput, , iFileSize)
[B][COLOR="Red"]cm.Parameters.Append cm.CreateParameter("@FileBlob", adVarBinary, adParamInput, iFileSize, mystream.Read)[/COLOR][/B]
cm.CommandType = adCmdText
cm.Execute
Set cm = Nothing
Debug.Print Format(pRecord, "#,##0") + " / " + Format(pRecords, "#,##0"), iFileSize, pPID, pFileID, sFullFileName
DoEvents
mystream.Close
conn.Close