Programmatically managing Microsoft Access Attachment-typed field with .NET

后端 未结 4 852
感动是毒
感动是毒 2020-12-09 13:14

Access added a new data type in the 2007 version--the Attachment type. We are currently working on a WinForms application with .NET 3.5 (C#) that uses an Access 2007 databas

4条回答
  •  -上瘾入骨i
    2020-12-09 13:47

    Interesting question. I don't use A2007, but have the runtime installed, so I used the Access object browser to see what's in there. I discovered something really odd -- there are two FIELD objects, Field and Field2. The attachment functions are members of Field2 but not Field. So, my suggestion would be that perhaps what you need to do is convert this:

    Recordset.Fields("FileData").LoadFromFile()
    

    to something like this:

    Dim rs As DAO.Recordset
    Dim fld2 As DAO.Field2
    
    Set rs = CurrentDb.OpenRecordset("[SQL]")
    Set fld2 = Recordset.Fields("FileData")
    fld2.LoadFromFile()
    
    rs.Close
    Set fld2=Nothing
    

    Now, I don't know if that will correct the problem for you, but it seems to me that given the two Field objects with different properties/methods/members, you need to be explicit about which Field object you're using. The code example you cite is specifically for use in Access and maybe Access does something to automatically resolve the differences between the two object (perhaps it uses the Field object by default for non-ACCDB databases and the Field2 object for ACCDB files).

提交回复
热议问题