简体   繁体   中英

How to read the varbinary (max) field value from SQL using VFP and Save it as pdf?

I am connecting my vfp applcication with SQL server. One table having the varbinary field and I need to read the binary and convert that into pdf file . How I can do that ?

Do you mean that the varbinary data itself is a PDF file (or any file)? If so just save the bytes you get to a file with a .PDF extension. ie:

Let's assume you have a table named "Files" in database "test" with fields like Id, FileExt and FileContent. FileExt holding the extension and FileContent is the file itself as varbinary(Max). You want to save all files to a folder named 'c:\\temp\\files':

Local handle, filename
handle = Sqlstringconnect("driver={Sql Server Native Client 11.0};server=.\SQLExpress;Database=test;Trusted_Connection=yes")

SQLExec(m.handle, 'Select * from [Files]', 'crsData')
SQLDisconnect(m.handle)

Select crsData
Scan
    fileName = Forcepath(Forceext(Ltrim(Str(crsData.Id)),Trim(crsData.FileExt)))
    Strtofile(crsData.FileContent, m.fileName, 'c:\temp\files')
Endscan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM