The picture to a binary form is written to the database mdb.

The controls on the form, 1 Adodc controls, 1 DataGrid, one image, 1 commond (image input), 1 common dialog
Requirements: display photos in the browsing history; open the common dialog box click "picture input", select the image file to write data to the database.
Question: after the operation error 3219, suggesting that: under the environment of this operation is not allowed. Code should be no problem, control problems? Or.Mdb files in the database have a problem? Please advice, thank you.

All the code is as follows:
Private Sub Command1_Click()
Dim strb() As Byte
Open CommonDialog1.FileName For Binary As #1
fl = LOF(1)
ReDim strb(f1)
Get #1, , strb
Adodc1.Recordset.Fields("Photo ").AppendChunk strb
Close #1
Image1.Picture = LoadPicture(CommonDialog1.FileName)
End Sub

Started by Abner at December 10, 2016 - 1:25 AM

I refer to this:

Use the save and display picture stream object
Open the VB6, new project.

Add two buttons, a image control
Note: the Access photo field in the type for the OLE object.
SqlServer in the photo field of type Image

'** Refer to Microsoft ActiveX Data Objects 2.5 Library and above version
'2.5 versions of the following does not support the Stream object
Dim iConcstr As String
Dim iConc As ADODB.Connection

'Save the file to the database
Sub s_SaveFile()
Dim iStm As ADODB.Stream
Dim iRe As ADODB.Recordset
Dim iConcstr As String

'Read the file content
Set iStm = New ADODB.Stream
With iStm
.Type = adTypeBinary 'Binary mode
.LoadFromFile App.Path + "\test.jpg"
End With

'Open the saved file table
Set iRe = New ADODB.Recordset
With iRe
.Open "select * from img", iConc, 1, 3
.AddNew 'Add a new record
.Fields("photo") = iStm.Read
End With

'After the completion of close objects
End Sub

Sub s_ReadFile()
Dim iStm As ADODB.Stream
Dim iRe As ADODB.Recordset
'Open the table
Set iRe = New ADODB.Recordset
'The new record
iRe.Open "select top 1 * from img order by id desc", iConc, adOpenKeyset, adLockReadOnly
'Save to file
Set iStm = New ADODB.Stream
With iStm
.Mode = adModeReadWrite
.Type = adTypeBinary
.Write iRe("photo")
'Here, if the current directory in test1.jpg, will offer a file write failed error.
.SaveToFile App.Path & "\test1.jpg"
End With

Image1.Picture = LoadPicture(App.Path & "\test1.jpg")
'Close the object
End Sub

Private Sub Command1_Click()
Call s_ReadFile
End Sub

Private Sub Command2_Click()
Call s_SaveFile
End Sub

Private Sub Form_Load()
'The database connection string
iConcstr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=F:\csdn_vb\database\ to save the picture to \access picture \img.mdb"

'The following statement is to connect to the SQLSERVER database.
'iConcstr = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _
' "User ID=sa;Password=;Initial Catalog=test;Data Source=yang"
Set iConc = New ADODB.Connection
iConc.Open iConcstr
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set iConc = Nothing
End Sub

Posted by Abby at December 14, 2016 - 1:57 AM

Your question should be no current record, or the record is not open

In addition
fl = LOF(1)
ReDim strb(f1)
This error, should be: ReDim strb(f1-1)

Posted by Buck at December 28, 2016 - 2:41 AM

A few days ago, this post by reference.

√ The picture to a binary form is written to the database mdb error [recommended] [Database (including printing, mounting, report)]

Posted by Andrea at January 02, 2017 - 3:39 AM

Dim sTemp As String

sTemp = "insert into mypic(pic) values(?) "

dim PicB() as byte

dim FileID as long


open "c:/test.bmp" for binary access read as #fileid

redim picb(lof(fileid))

get fileid,,picb

close #fileid

dim Con as new connection

dim CMD as new command

con.connectionstring ="The database connection string"


cmd.commandtext= stemp






set cmd=nothing

set con=nothing

Posted by Yvonne at January 09, 2017 - 4:11 AM