Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is what I use to get the file attachments from an OleDB connection in .net code to a microsoft access database with attachment field types:</p> <p>This method gets the file you want in Ordinal Position from the attachment field name "Pic" in my table.. you can store many files in the attachment field, so you have to specify which of the files you want.. hope this helps ( i use this as web url to take the image from the attachment field in the access database, but the COM calls will be the same in your winform app)..good luck</p> <pre><code> try { //You get your file in a byteArray fileType is just the ordinal file position in the fileattachment field..ex. 1, 2, 3 (shown in the access listbox) Response.BinaryWrite(GetPicField(productID, fileType)); Response.ContentType = "image/bmp"; } catch { //need to get missing product photo image here as well N/A Response.BinaryWrite(GetNA_Image()); Response.ContentType = "image/bmp"; } //getting from Database private byte[] GetPicField(string productID,int fileToShow) { DBEngine dbe = new DBEngine(); Database db; Recordset rs; byte[] byteArray = null; dbe = new DBEngine(); db = dbe.OpenDatabase(Application["DB_FileName"].ToString()); rs = db.OpenRecordset("SELECT PIC FROM PRODUCT WHERE PRODUCTID = " + productID, RecordsetTypeEnum.dbOpenForwardOnly, 0, LockTypeEnum.dbPessimistic); if (rs.RecordCount &gt; 0) { Recordset rs2 = (Recordset2)rs.Fields["Pic"].Value; int i = 1; while (i &lt; fileToShow) { rs2.MoveNext(); i++; } //get the thubmnail Field2 f2 = (Field2)rs2.Fields["FileData"]; //0 is first pic byteArray = f2.GetChunk(20, f2.FieldSize - 20); System.Runtime.InteropServices.Marshal.ReleaseComObject(f2); rs2.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(rs2); f2 = null; rs2 = null; } rs.Close(); db.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); System.Runtime.InteropServices.Marshal.ReleaseComObject(dbe); System.Runtime.InteropServices.Marshal.ReleaseComObject(db); rs = null; db = null; dbe = null; return byteArray; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload