Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save picture in BLOB format?
    text
    copied!<p>I did code for procedure that prompts for a .jpeg file, converts that file to a Byte array, and saves the Byte Array to the table using the Append chunk method. Another procedure retrieves the picture image from the table using the GetChunk method, converts the data to a file and displays that file in the Picture box.</p> <p>Now, my question is that how do I save that image displayed in picture box into the database, so that I can perform operations like: add/update etc. I did something like this way:</p> <pre><code>Private Sub CmdSave_Click() if(cmbRNO=" ") then sql = "INSERT INTO STUDENT_RECORD_DATABASE(ROLLNO,PICS)" sql = sql + "VALUES(" &amp; RNo &amp; ","&amp; picture1.picture &amp;")" Set RES = CON.Execute(sql) Else sql = "UPDATE STUDENT_RECORD_DATABASE SET " sql = sql + "ROLLNO= " &amp; Val(CmbRNO) &amp; "," sql = sql + "PICS=" &amp; Picture1.Picture &amp; " " sql = sql + "WHERE ROLLNO= " &amp; Val(CmbRNO) &amp; "" Set RES = CON.Execute(sql) End If End Sub &lt;code for appendchunk method&gt; Public Sub Command1_Click() Dim PictBmp As String Dim ByteData() As Byte 'Byte array for Blob data. Dim SourceFile As Integer ' Open the BlobTable table. strSQL = "Select ID, DOC from LOB_TABLE WHERE ID = 1" Set Rs = New ADODB.Recordset Rs.CursorType = adOpenKeyset Rs.LockType = adLockOptimistic Rs.Open strSQL, Cn ' Retrieve the picture and update the record. CommonDialog1.Filter = "(*.jpeg)|*.jpeg" CommonDialog1.ShowOpen PictBmp = CommonDialog1.FileName ' Save Picture image to the table column. SourceFile = FreeFile Open PictBmp For Binary Access Read As SourceFile FileLength = LOF(SourceFile) ' Get the length of the file. If FileLength = 0 Then Close SourceFile MsgBox PictBmp &amp; " empty or not found." Exit Sub Else Numblocks = FileLength / BlockSize LeftOver = FileLength Mod BlockSize ReDim ByteData(LeftOver) Get SourceFile, , ByteData() Rs(1).AppendChunk ByteData() ReDim ByteData(BlockSize) For i = 1 To Numblocks Get SourceFile, , ByteData() Rs(1).AppendChunk ByteData() Next i Rs.Update 'Commit the new data. Close SourceFile End If End Sub </code></pre> <p>While trying to save image to specific record, run-time error occurs: inconsistent datatype,expected BLOB got number Where as: ?sql UPDATE STUDENT_RECORD_DATABASE SET ROLLNO= 132,PICS=688195876 WHERE ROLLNO= 132</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload