Requirements: to show photos when browsing history; Click "image input" general open dialog box, select specify image files to write data into the database,
Problem: run after prompt error 3219, tip: don't allow operation in this environment, the code should be no problem to control the problem? Or. The MDB file database has a problem? Please comment, thank you,
All the code is as follows:
Private Sub Command1_Click ()
Dim STRB () As Byte
CommonDialog1. ShowOpen
The Open CommonDialog1. The FileName For Binary As # 1
Fl=LOF (1)
ReDim STRB (f1)
Get the # 1, STRB
Adodc1. You. Fields (" photos "). AppendChunk STRB
Close # 1
Image1. Picture=LoadPicture (CommonDialog1. FileName)
End Sub
CodePudding user response:
Refer to the building Lord:Use the stream object is to save and display pictures
Open the vb6, new construction,
Add the two button, an image control
Note: photo of Access field type as OLE object.
Essentially a photo of the field type for Image
'* * refer to Microsoft ActiveX Data Objects Library 2.5 and above version
'the 2.5 version 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 the ADODB library you
Dim iConcstr As String
'read the file
The Set iStm=New ADODB. Stream
With iStm
The binary mode
=adTypeBinary '. Open
. The LoadFromFile App. Path + "\ test. JPG"
End With
'open file table
The Set iRe (=New ADODB. You
With iRe (
. Open the select * from "img", iConc, 1, 3
. AddNew 'add a record
Fields (" photo ")=iStm. Read
. The Update
End With
'after the completion of the closing object
IRe (. Close
IStm. Close
End Sub
Sub s_ReadFile ()
Dim iStm As ADODB. Stream
Dim iRe (As the ADODB library you
'open the table
The Set iRe (=New ADODB. You
'to get the latest record of add
IRe (. Open the "select * from top 1 img order by id desc", iConc, adOpenKeyset, adLockReadOnly
'save to file
The Set iStm=New ADODB. Stream
With iStm
The Mode=adModeReadWrite
. Type=adTypeBinary
. Open
The.write iRe ((" photo ")
'attention here, if the current directory exists test1. JPG, will report the failure of a file is written to mistakes.
. SaveToFile App. Path & amp; "\ test1. JPG"
End With
Image1. Picture=LoadPicture (App) Path & amp; "\ test1 JPG")
'close the object
IRe (. Close
IStm. Close
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. The OLEDB. 4.0. Persist Security Info=False "& amp; _
"; Data Source=F: \ csdn_vb \ database to save the file \ \ access images \ img MDB
"
'the following statement is essentially a database.
'iConcstr="Provider=SQLOLEDB. 1; Persist Security Info=True;" & _
'" the User ID=sa; Password=; Initial Catalog=test; Data Source=Yang "
The Set iConc=New ADODB. Connection
IConc. Open iConcstr
End Sub
Private Sub Form_Unload (Cancel As Integer)
IConc. Close
The Set iConc=Nothing
End Sub
CodePudding user response:
Your question should be no current records, or record did not openIn addition
Fl=LOF (1)
ReDim STRB (f1)
This mistake, it should be: ReDim STRB - 1 (f1)
CodePudding user response:
The other day this post reference: by the way,http://bbs.csdn.net/topics/390546962
Square root error will be written to the database in the form of binary picture MDB [recommend] [database (include printing, installation, reports)]
CodePudding user response:
http://download.csdn.net/detail/veron_04/1483930CodePudding user response:
http://blog.csdn.net/vansoft/article/details/3667917CodePudding user response:
Dim sTemp As String
STemp="insert into mypic (PIC) values (?) "
Dim PicB () as byte
Dim a count as long
A count=freefile
Open "c:/test. BMP" for binary access read as # a count
Redim picb (lof (count))
Get a count, picb
Close # count
Dim Con as new connection
Dim CMD as new command
Con. The connectionstring="database connection string"
Con. Open
CMD. The activeconnection=con
Cmd.com mandtext=stemp
Cmd.com mandtype=adcmdtext
CMD. The parameters (0). The type=adbinary
CMD. The parameters (0). value=https://bbs.csdn.net/topics/picb
CMD. The execute
Con. Close
The set of CMD=nothing
The set of con=nothing