2015-01-04 3 views
2

AxHost.GetPictureFromIPicture()를 사용하여 MS Access 2013 데이터베이스 파일에서 첨부 파일 형식으로 저장 한 GIF 이미지를 가져 오려고합니다. * .accdb) - 이미지로 변환하여 PictureBox에 표시 할 수 있습니다. 그러나 방법은 거기 있지 않습니다! 내가 뭔가를 놓치고 있습니까? 설치 또는 설치해야합니까?AxHost.GetPictureFromIPicture() 메서드가 누락되었습니다. MS Access 데이터베이스에서 그림 (첨부 파일)을 검색하고 있습니다.

변환하지 않고이 오류 메시지가 나타납니다. " 'System .__ ComObject'형식의 COM 개체를 'System.Drawing.Image'클래스 유형으로 캐스팅 할 수 없습니다. "

는 사실은 모든 것이 올바른 방법으로해야합니까? 아니면 더 나은 솔루션이있다?, 저를 도와주세요.

DBEngine dbe = new DBEngine(); 
Database db = dbe.OpenDatabase("Database1.accdb", false, false, ""); 
Recordset rs = db.OpenRecordset("select solution from tab2 where id = 1", RecordsetTypeEnum.dbOpenDynaset, 0, LockTypeEnum.dbOptimistic); 
rs.MoveFirst(); 

object o = rs.Fields[0].Value; 
Image img = (Image)o; -> error 
Image img = AxHost.GetPictureFromIPicture(o); - the method is missing 
pictureBox1.Image = img; 

rs.Close(); 

답변

2

AxHost Class에 대한 문서는

You typically do not use the AxHost class directly. You can use the Windows Forms ActiveX Control Importer (Aximp.exe) to generate the wrappers that extend AxHost.

을 말한다 0

나는 그 접근법을 시도하지 않았다는 것을 인정해야한다. 내가 아는 한 Access 데이터베이스의 첨부 파일 필드에서 파일을 안정적으로 추출하는 유일한 방법은 ACE DAO Field2 개체의 .SaveToFile() 메서드를 사용하는 것입니다. 귀하의 경우 코드는 다음과 같습니다.

public partial class Form1 : Form 
{ 
    string tempFileName; 
    Image img; 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     DBEngine dbe = new DBEngine(); 
     Database db = dbe.OpenDatabase(@"C:\Users\Public\AttachmentsDB.accdb"); 
     Recordset rsMain = db.OpenRecordset(
       "select solution from tab2 where id = 1", 
       RecordsetTypeEnum.dbOpenSnapshot); 
     Recordset2 rsAttach = rsMain.Fields["solution"].Value; 
     tempFileName = System.IO.Path.GetTempPath() + "\\" + rsAttach.Fields["FileName"].Value; 
     try 
     { 
      System.IO.File.Delete(tempFileName); 
     } 
     catch { } 
     Field2 fldAttach = (Field2)rsAttach.Fields["FileData"]; 
     fldAttach.SaveToFile(tempFileName); 
     rsAttach.Close(); 
     rsMain.Close(); 
     db.Close(); 
     img = Image.FromFile(tempFileName); 
     pictureBox1.Image = img; 
    } 

    private void Form1_FormClosed(object sender, FormClosedEventArgs e) 
    { 
     img.Dispose(); 
     System.IO.File.Delete(tempFileName); 
    } 

}