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

  • Discussion générale

  • 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

    • Type modifié vb.neter jeudi 23 janvier 2014 21:24
    • Modifié vb.neter dimanche 26 janvier 2014 17:32
    jeudi 23 janvier 2014 20:40

Toutes les réponses

  • 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.

    lundi 27 janvier 2014 07:14