Reading attached files from database using OLE-DB

后端 未结 2 1799
野趣味
野趣味 2020-12-21 16:52

I\'m trying to read a Microsoft Access Database using C#. I\'m using the OLE-DB classes. The Problem is that this code

OleDbDataReader reader = Command.Execu         


        
2条回答
  •  醉梦人生
    2020-12-21 17:00

    I realise you asked for OleDb, but with DAO you could say something like:

        DBEngine dbe = new DBEngine();
        Database db = dbe.OpenDatabase(@"z:\docs\test.accdb", false, false, "");
        Recordset rs = db.OpenRecordset("SELECT TheAttachment FROM TheTable", 
            RecordsetTypeEnum.dbOpenDynaset, 0, LockTypeEnum.dbOptimistic);
    
        Recordset2 rs2 = (Recordset2)rs.Fields["TheAttachment"].Value;
    
        Field2 f2 = (Field2)rs2.Fields["FileData"];
        f2.SaveToFile(@"z:\docs\ForExample.xls");
        rs2.Close();
        rs.Close();
    

    Reference: Programmatically managing Microsoft Access Attachment-typed field with .NET

提交回复
热议问题