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

  • 일반 토론

  • 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

    • 유형 변경됨 vb.neter 2014년 1월 23일 목요일 오후 9:24
    • 편집됨 vb.neter 2014년 1월 26일 일요일 오후 5:32
    2014년 1월 23일 목요일 오후 8:40

모든 응답

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

    2014년 1월 27일 월요일 오전 7:14