Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21266

[RESOLVED] Save Image to SQL DB and retrieve it?

$
0
0
dears, I'm successfully save image to SQL DB and try to retrieve it but with error message as follow:
( Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another) and highlight on red code below. Please any advice to get it solved? Thank you in advance.

below code i used to save image to DB:
Code:

Private Sub SavePic2SQLDB(ByRef tempRS As ADODb.Recordset)
  Dim iFileNum As Integer
  Dim lFileLength As Long
  Dim abBytes() As Byte
  Dim sTempFile As String
 
  sTempFile = txtPixPath.Text

 'read file contents to byte array
    iFileNum = FreeFile
    Open sTempFile For Binary Access Read As #iFileNum
    lFileLength = LOF(iFileNum)
    ReDim abBytes(lFileLength)
    Get #iFileNum, , abBytes()
    'put byte array contents into db field
    tempRS.Fields("Image").AppendChunk abBytes()
    Close #iFileNum

End Sub

Also, below code i used to load image from DB:
Code:

Private Sub LoadPicFromSQLDB(ByRef tempRS As ADODb.Recordset)
      Dim iFileNum As Integer
      Dim iFileLength As Long
      Dim abBytes() As Byte
      Dim sTempFile As String
      Dim rsReceived As ADODb.Recordset

      sTempFile = App.path & "\pix\" & Format(Now, "yyyymmddhhnnss") & ".jpg"
 
      iFileNum = FreeFile
      Open sTempFile For Binary As #iFileNum
      iFileLength = LenB(tempRS("Image"))
      ReDim abBytes(iFileLength)
      abBytes = tempRS("Image").GetChunk(iFileLength) 
      Put #iFileNum, , abBytes()
      Close #iFileNum

      If Not sTempFile = "" Then
        Set curPicture = LoadPicture(sTempFile)
 
        If Not curPicture Is Nothing Then
            Image1.Picture = curPicture
     
        End If
      End If
     
      '=== delete the temp file away ====
      Kill sTempFile
     
End Sub


Viewing all articles
Browse latest Browse all 21266

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>