Accessing files in a database

Source: Internet
Author: User
Accessing files in a database
Http://www.51cto.com by: pconline
This article describes how to use ADO to operate files in a database.

'*************************************** * *************** Use ADODB. stream saves/reads files to the database '** reference Microsoft ActiveX Data Objects 2.5 library and later' *** '** ----- database connection string template -------------------------------------------' ** Access Database '** iconcstr = "provider = Microsoft. jet. oledb.4.0; persist Security info = false "& _ '**"; Data Source = database name "' *** sqldatabase' ** 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 'database connection string iconcstr = "provider = Microsoft. jet. oledb.4.0; persist Security info = false "& _"; Data Source = F: \ My Documents \ customer profile 1.mdb" 'reads the file to the content set istm = adonew dB. stream with istm. type = adtypebinary 'binary mode. open. loadfromfile "C: \ test.doc" end with 'Open the table set ire = new ADODB. recordset with ire. open "table", iconc, adopenkeyset, adlockoptimistic. addnew' adds a record. fields ("fields for saving file content") = istm. read. update end with 'Close the object ire after completion. close istm. close end sub 'read 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 'database connection string iconc = "provider = Microsoft. jet. oledb.4.0; persist Security info = false "& _"; Data Source =\\ xz \ C $ \ Inetpub \ ZJ. mdb "'Open the 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 'Close the object ire. close istm. close end sub

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.