Save and retrieve PDF file in MS Access VB.NET RRS feed

  • General discussion

  • I am using with MS Access 2010. I want to retrieve PDF and read the pdf file when clicking the button in the form.

    Save file to MS Access database

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)       Handles select_file.Click
     With ofdpdf
           .InitialDirectory = "C:"
            .Filter = "PDF|*.pdf"
            .FileName = ?
        End With
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

    Try Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\BCInventory.accdb;Persist Security Info=False;") conn.Open() Dim command As New OleDbCommand("insert into pdf ([pdfID], [PR], [Year], [File]) values (@pdfID, @pr, @year, @pdfFile)", conn) With command.Parameters .AddWithValue("@pdfID", lbllogoid.Text) .AddWithValue("@pr", txtpr.Text) .AddWithValue("@year", txtyear.Text) Try Dim fs As New FileStream(fpath.Text, FileMode.Open, FileAccess.Read) Dim byteArr(CInt(fs.Length)) As Byte fs.Read(byteArr, 0, fs.Length) fs.Close() .AddWithValue("@pafFile", byteArr) Catch ex As Exception MsgBox(ex.ToString) End Try End With command.ExecuteNonQuery() MessageBox.Show("FIle saved", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information) command.Dispose() conn.Close() clear() End Using Catch ex As Exception MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try

    End Sub

    • Changed type vb.neter Thursday, January 23, 2014 9:24 PM
    • Edited by vb.neter Sunday, January 26, 2014 5:32 PM
    Thursday, January 23, 2014 8:40 PM

All replies

  • Hi,

    I haven't checked your code carefully however it is obviously you should post related VB code issue to

    If it is not a question and you are sharing your experience, you'd better change your title.


    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 27, 2014 7:14 AM