Центр разработки для Windows

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 23 января 2014 г. 21:24
    • Изменено vb.neter 26 января 2014 г. 17:32
    23 января 2014 г. 20:40

Все ответы