Note that there are some explanatory texts on larger screens.

plurals
  1. POStore Byte[] in Access 2010
    primarykey
    data
    text
    <p>Such a simple task: <strong>How to store a Byte[] in Access 2010?</strong> (Searching the web all day long about this.)</p> <p>I have to use a "Attachment Field" in access 2010 because as far as i can see there is no other possible (varBinary, Image,..) field available.</p> <p>I tried: (ConvertImageToByte returns a Byte[])</p> <pre><code> Cmd.CommandText = "UPDATE Clubs SET Field1 = @File WHERE Name = @Name"; OleDbParameter para = new OleDbParameter("@File", OleDbType.VarBinary); para.Value = ConvertImageToByte(Logo); Cmd.ExecuteNonQuery(); </code></pre> <p>Exception: "An UPDATE or DELETE query cannot contain a multi-valued field."</p> <p>I tried:</p> <pre><code> DBEngine dbe = new DBEngine(); Database db = dbe.OpenDatabase("database.accdb", false, false, ""); String Command = "SELECT * FROM Clubs"; Recordset rs = db.OpenRecordset(Command, RecordsetTypeEnum.dbOpenDynaset, 0, LockTypeEnum.dbOptimistic); rs.MoveFirst(); rs.Edit(); Recordset2 rs2 = (Recordset2)rs.Fields["Field1"].Value; rs2.AddNew(); Field2 f2 = (Field2)rs2.Fields["FileData"]; f2.LoadFromFile("file.png"); rs2._30_Update(); rs2.Close(); rs._30_Update(); rs.Close(); </code></pre> <p>This works but the file is in the first row of the tabel all the time and i can´t figure out how to get the right row. If i try to add a WHERE clause to the SELECT statement ill get a " Too few parameters. Expected 2." exception.</p> <p><em>If anyone knows a way to story my Byte[] (or a image) into the database an get it out again please let me know!</em></p> <p><strong>Please don´t give me links to:</strong></p> <p><a href="http://office.microsoft.com/en-us/access-help/using-multivalued-fields-in-queries-HA010149297.aspx#BM4.6" rel="nofollow noreferrer">http://office.microsoft.com/en-us/access-help/using-multivalued-fields-in-queries-HA010149297.aspx#BM4.6</a></p> <p><a href="http://www.mikesdotnetting.com/Article/123/Storing-Files-and-Images-in-Access-with-ASP.NET" rel="nofollow noreferrer">http://www.mikesdotnetting.com/Article/123/Storing-Files-and-Images-in-Access-with-ASP.NET</a></p> <p><a href="http://www.sitepoint.com/forums/showthread.php?t=666928" rel="nofollow noreferrer">http://www.sitepoint.com/forums/showthread.php?t=666928</a></p> <p><a href="http://www.eggheadcafe.com/software/aspnet/35103540/multivalued-fields-in-access-2007-with-c-ado.aspx" rel="nofollow noreferrer">http://www.eggheadcafe.com/software/aspnet/35103540/multivalued-fields-in-access-2007-with-c-ado.aspx</a></p> <p><a href="https://stackoverflow.com/questions/779211/programmatically-managing-microsoft-access-attachment-typed-field-with-c-net">Programmatically managing Microsoft Access Attachment-typed field with .NET</a></p> <p>Thanks for your help guys.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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