从 MS Access 2007 DB (VB.net) 下载文件

发布于 2024-12-29 07:33:04 字数 156 浏览 7 评论 0 原文

您好,我正在使用 VB.net 创建一个 Windows 应用程序,我想知道如何创建一个下载按钮,以便当用户单击它时,它能够从数据库中的附件列下载特定附件。

我试图用谷歌搜索如何去做这件事,但不幸的是,我仍然找不到答案。如果有这方面经验的人能够指导我编写此函数的过程,我将不胜感激。

Hi I am creating a windows application using VB.net and I would like to know how I can go about creating a download button so that when the user clicks it, it is able to download the specific attachment from the attachment column in the database.

I have tried to google on how I can go about doing this but unfortunately still, I am not able to find that answer. I appreciate it if someone with experience in this could guide me in the process of coding this function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软的没边 2025-01-05 07:33:04

使用 DAO(添加 Microsoft.Office.Interop.Access.Dao.DLL 的引用)从 Ms-Access 数据库读取附件字段。

示例代码:

Imports Microsoft.Office.Interop.Access
Public Class Form1
   Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim FileName = "c:\WindowsApplication1\Database1.accdb"

        'Directory location where attachment files will be stored.
        Dim Path = "c:\WindowsApplication1\"

        Dim engine As New Dao.DBEngine
        Dim database As Dao.Database = engine.OpenDatabase(FileName)

        Dim rs As Dao.Recordset = database.OpenRecordset("select MyAttachmentField from  TableName")
        While Not rs.EOF
            Dim rs1 As Dao.Recordset2 = rs.Fields("MyAttachmentField").Value
            While Not rs1.EOF
                Dim fName As String = Path & rs1("FileName").Value
                Dim fld As Dao.Field2 = rs1("FileData")
                'Delete a file if same named file exists
                System.IO.File.Delete(fName)
                fld.SaveToFile(fName)
                rs1.MoveNext()
            End While
         rs.MoveNext()
        End While
    End Sub
End Class

Use DAO (Add the reference of Microsoft.Office.Interop.Access.Dao.DLL ) to read attachment field from the Ms-Access database.

Sample code:

Imports Microsoft.Office.Interop.Access
Public Class Form1
   Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim FileName = "c:\WindowsApplication1\Database1.accdb"

        'Directory location where attachment files will be stored.
        Dim Path = "c:\WindowsApplication1\"

        Dim engine As New Dao.DBEngine
        Dim database As Dao.Database = engine.OpenDatabase(FileName)

        Dim rs As Dao.Recordset = database.OpenRecordset("select MyAttachmentField from  TableName")
        While Not rs.EOF
            Dim rs1 As Dao.Recordset2 = rs.Fields("MyAttachmentField").Value
            While Not rs1.EOF
                Dim fName As String = Path & rs1("FileName").Value
                Dim fld As Dao.Field2 = rs1("FileData")
                'Delete a file if same named file exists
                System.IO.File.Delete(fName)
                fld.SaveToFile(fName)
                rs1.MoveNext()
            End While
         rs.MoveNext()
        End While
    End Sub
End Class
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文