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

  • 全般的な情報交換

  • I am using vb.net 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日 21:24
    • 編集済み vb.neter 2014年1月26日 17:32
    2014年1月23日 20:40

すべての返信

  • Hi,

    I haven't checked your code carefully however it is obviously you should post related VB code issue to http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral

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

    Regards,



    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
    モデレータ