首页 > 解决方案 > 在 Adob​​e 阅读器工具中显示和查看 pdf 文件

问题描述

我使用代码在 adobe reader 工具中查看 pdf 文件,然后将它们存储在 sql server 数据库中,我想要的是一种在 datagridview 中双击文件名时显示这些存储文件的方法我使用此代码显示 pdf 文件:

Private Sub btnNewItem_Click(sender As Object, e As EventArgs) Handles btnNewItem.Click

        txtItemNO.Text = GetmaxID()

        btnSaveItem.Enabled = True

        ofd.Filter = "pdf Files|*.pdf"
        If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
            txtpdfPath.Text = ofd.FileName
            AxAcroPDF1.src = txtpdfPath.Text
        End If

    End Sub

这段代码将它们保存在数据库中:

 Private Sub btnSaveItem_Click(sender As Object, e As EventArgs) Handles btnSaveItem.Click

        Try
            cmd = New SqlCommand("insert into TBL_Attaches (AttachID, AttachName, AttachDate, Picture, CatID) values (@AttachID, @AttachName, @AttachDate, @Picture, @CatID)", con)

            con.Open()
            With cmd.Parameters
                .AddWithValue("@AttachID", txtItemNO.Text)
                .AddWithValue("@AttachName", txtItemName.Text)
                .AddWithValue("@AttachDate", dtDateSave.Value)

                Dim fs As New FileStream(ofd.FileName, FileMode.Open, FileAccess.Read)
                Dim br As New BinaryReader(fs)
                Dim Filepdf() As Byte = br.ReadBytes(br.BaseStream.Length)
                .AddWithValue("@Picture", Filepdf)

                .AddWithValue("@CatID", cmbItemCat.SelectedValue)
            End With
            cmd.ExecuteNonQuery()
            MsgBox("Done!", MsgBoxStyle.Information, "Save")

            dgsittings()

        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            con.Close()
        End Try
    End Sub

这是我用来在 datagridview 中显示文件名的代码:

        adapter = New SqlDataAdapter("select TBL_Attaches.AttachID, TBL_Attaches.AttachName, TBL_Attaches.AttachDate, TBL_CatFailes.CatName from TBL_Attaches inner join TBL_CatFailes on TBL_Attaches.CatID = TBL_CatFailes.CatID", con)
        Dim dtG As New DataTable
        adapter.Fill(dtG)
        dgAttached.DataSource = dtG

当我在datagridview中双击它的名称时,我只想显示pdf文件

标签: vb.net

解决方案


推荐阅读