VB reads binary images and long text of SQL Server

Source: Internet
Author: User
Dim RS as new ADODB. recordset
Dim conn as new ADODB. Connection

Private sub form_load ()
Conn. Open "provider = sqloledb.1; persist Security info = false; user id = sa; Password = 1234; initial catalog = kepu; Data Source = founder"
Rs. Open "news", Conn, 3, adlockoptimistic, adcmdtable
End sub

Private sub commandementclick ()

Dim stmpic as ADODB. Stream
'On error goto err

Set rs = conn. Execute ("select imgsize, newsid, IMG from News ")
Strpath = "D:/image"
Set stmpic = new ADODB. Stream


Dim strfilename as string

Rs. movenext

While not Rs. EOF

If Rs. Fields ("imgsize")> 0 then' has a graph
Strfilename = strpath + "/kepu" + STR (Rs. Fields ("newsid") + ". jpg"


With stmpic
. Type = adtypebinary
. Open
. Write Rs. Fields ("IMG") 'writes data in the database to the stream.
. Savetofile strfilename, adsavecreateoverwrite 'write the data in stream to the temporary file.
. Close
End

Else

End if
Rs. movenext


Wend

Msgbox "image exported"

Rs. Close

'Picture2. Picture = loadpicture (strpictemp) 'use the picture control to display images
Exit sub
Err:
Msgbox err. Description

End sub

Private sub command2_click ()
Dim strcontent as ADODB. Stream
'On error goto err

Set rs = conn. Execute ("select newsid, content from News ")
Strpath = "D:/html"
Set strcontent = new ADODB. Stream


Dim strfilename as string

Rs. movenext

While not Rs. EOF

Strfilename = strpath + "/kepu" + STR (Rs. Fields ("newsid") + ". htm"


With strcontent
. Type = adtypetext
. Open

. Writetext Rs! Content 'write the data in the database to the stream
. Savetofile strfilename, adsavecreateoverwrite 'write the data in stream to the temporary file.
. Close

End

Rs. movenext


Wend

Msgbox "content exported"

Rs. Close

'Picture2. Picture = loadpicture (strpictemp) 'use the picture control to display images
Exit sub
Err:
Msgbox err. Description

End sub

Related Article

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.