this is my code , it should save a pdf file from sql server to a folder but nothing happened can anyone help please ??

Set rs = New ADODB.Recordset
rs.Open "select * from PDFStore where filename='" & co_name.Text & "'", db, adOpenKeyset, adLockBatchOptimistic
If Not rs.EOF Then

Set pdffile = New ADODB.Stream
pdffile.Type = adTypeBinary
pdffile.Open
If IsNull(rs.Fields("Contents")) = False Then
pdffile.Write rs.Fields("Contents").Value
Dim pdfname As String
pdfname = co_name.Text
pdffile.SaveToFile "" & App.Path & "\report\" & pdfname & ".pdf", adSaveCreateOverWrite
pdffile.Close
Set pdffile = Nothing
Else
MsgBox "NO"
rs.Close
Set rs = Nothing

End If

End If

Recommended Answers

All 6 Replies

The first thing I'd do is set a breakpoint at the first line you posted, and step through the code as it runs. Have you tried this? It should give us a better idea of what's actually happening.

what i do i saved a pdf file in sql server 2008 and now i need to retrieve the file from the sql and save it to folder in project path to open it , i dont know how i can retrive by open directly the file or save it in a folder ,

What does "nothing happened" mean? I assume you at least ran the code you posted. It looks like it should retrieve PDF content and save it to a file, but it doesn't open the file for viewing. Was the file created?

no nothing created with no error?? still have the problem

Have you tried setting a breakpoint and stepping through to see if your code is even running?

yes i do

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.