Code for accessing files in a database implemented by ASP-application techniques
Source: Internet
Author: User
*************************************************************************
'**
' * * Use ADODB. Stream save/Read files to database
' * * Reference the Microsoft ActiveX Data Objects 2.5 Library and the above version
'**
' * *-----database connection string Template---------------------------------------
' * * Access database
' * * iconcstr = provider=microsoft.jet.oledb.4.0; Persist Security Info=false "& _
' * * ";D ATA source= database name"
'**
' * * SQL database
' * * iconcstr = Provider=SQLOLEDB.1; Persist security Info=true; "& _
' * * ' user id= username; password= password; Initial catalog= database name; Data source=sql server name "
'**
'*************************************************************************
'
' 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 to the content
Set IStm = New ADODB. Stream
With IStm
. Type = adTypeBinary ' binary mode
. Open
. LoadFromFile "C:\Test.doc"
End With
' Open the saved file's table
Set iRe = New ADODB. Recordset
With IRe
. Open "Table", Iconc, adOpenKeyset, adLockOptimistic
. AddNew ' Add a record
. Fields ("Fields to save file contents") = Istm.read
. Update
End With
' Close object when finished
Ire.close
Istm.close
End Sub
' Read the data from the database and save it as a file
Sub S_readfile ()
Dim IStm as ADODB. Stream
Dim IRe as ADODB. Recordset
Dim Iconc as String
' Open Table
Set iRe = New ADODB. Recordset
Ire.open "Tb_img", Iconc, adOpenKeyset, adLockReadOnly
Ire.filter = "Id=64"
' Save to File
Set IStm = New ADODB. Stream
With IStm
. Mode = adModeReadWrite
. Type = adTypeBinary
. Open
. Write iRe ("img")
. SaveToFile "C:\Test.doc"
End With
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service