BKennedy2008
asked on
wrting multiple PDF's (stored as SQL Images) to a selected folder in VB
I need to write multiple PDF receipts stored as images in a SQL DB to a destination folder.
Below will handle 1 PDF, but I need to handle multiple pdf's to create my invoice.
any ideas? I imagine rewriting the SQL statement to select ReceiptID, BinaryData....and putting it in a Datatable and then reading the DT in a Do/Loop
Dim myconnection As String = My.Settings.LaborSheetsCon nectionStr ing
Dim connection As New SqlConnection(myconnection )
Dim strSql As String
connection.Open()
strSql = "Select BinaryData from SubcontractorInvoicing where JobNumber = '" & JobNumberHolder & "' and Fileuploaded = 'True' and ExpenseDate >= '" & BeginDateI & "' and ExpenseDate <= '" & EndDateI & "'"
Dim sqlCmd As New SqlCommand(strSql, connection)
'Get image data from DB
Dim fileData As Byte() = DirectCast(sqlCmd.ExecuteS calar(), Byte())
Dim sTempFileName As String = DestinationFolder_Invoice. Text & "\H_" & intSecond & ".pdf"
'Read image data into a file stream
Using fs As New FileStream(sTempFileName, FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(fileData, 0, fileData.Length)
'Set image variable value using memory stream.
fs.Flush()
fs.Close()
End Using
connection.Close()
Below will handle 1 PDF, but I need to handle multiple pdf's to create my invoice.
any ideas? I imagine rewriting the SQL statement to select ReceiptID, BinaryData....and putting it in a Datatable and then reading the DT in a Do/Loop
Dim myconnection As String = My.Settings.LaborSheetsCon
Dim connection As New SqlConnection(myconnection
Dim strSql As String
connection.Open()
strSql = "Select BinaryData from SubcontractorInvoicing where JobNumber = '" & JobNumberHolder & "' and Fileuploaded = 'True' and ExpenseDate >= '" & BeginDateI & "' and ExpenseDate <= '" & EndDateI & "'"
Dim sqlCmd As New SqlCommand(strSql, connection)
'Get image data from DB
Dim fileData As Byte() = DirectCast(sqlCmd.ExecuteS
Dim sTempFileName As String = DestinationFolder_Invoice.
'Read image data into a file stream
Using fs As New FileStream(sTempFileName, FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(fileData, 0, fileData.Length)
'Set image variable value using memory stream.
fs.Flush()
fs.Close()
End Using
connection.Close()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the quick response
ASKER
Dim myconnection As String = My.Settings.LaborSheetsCon
Dim connection As New SqlConnection(myconnection
Dim strSql As String
connection.Open()
strSql = "Select FileName, BinaryData from SubcontractorInvoicing where JobNumber = '" & JobNumberHolder & "' and Fileuploaded = 'True' and ExpenseDate >= '" & BeginDateI & "' and ExpenseDate <= '" & EndDateI & "'"
Dim sqlCmd As New SqlCommand(strSql, connection)
'Get image data from DB
' Dim fileData As Byte() = DirectCast(sqlCmd.ExecuteS
Dim rst As SqlDataReader = sqlCmd.ExecuteReader
While rst.Read
Dim fileData As Byte() = rst("BinaryData")
Dim FileName As String = rst("FileName")
Dim sTempFileName As String = DestinationFolder_Invoice.
'Read image data into a file stream
Using fs As New FileStream(sTempFileName, FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(fileData, 0, fileData.Length)
'Set image variable value using memory stream.
fs.Flush()
fs.Close()
End Using
End While
connection.Close()