本文介绍了存储字节] Access 2010中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这样一个简单的任务:如何到一个byte []存储在Access 2010 (搜索网页整天关于这一点)Such a simple task: How to store a Byte[] in Access 2010? (Searching the web all day long about this.)我必须使用一个附件栏在2010年访问,因为据我可以看到没有可用的其他可能的(VARBINARY,图片,..)场。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.我想:(ConvertImageToByte返回一个字节[])I tried: (ConvertImageToByte returns a Byte[]) Cmd.CommandText = "UPDATE Clubs SET Field1 = @File WHERE Name = @Name"; OleDbParameter para = new OleDbParameter("@File", OleDbType.VarBinary); para.Value = ConvertImageToByte(Logo); Cmd.ExecuteNonQuery(); 例外:UPDATE或DELETE查询不能包含一个多值字段Exception: "An UPDATE or DELETE query cannot contain a multi-valued field."我试过: 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();这工作,但该文件是TABEL的第一行中的所有的时间和我不能弄清楚如何得到正确的行。如果我尝试WHERE子句添加到SELECT语句生病得到一个太少参数。预期2。例外。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.的如果有人知道的方式来报道我的字节[](或图像)插入到数据库中再次把它弄出来,请让我知道! 请鸵鸟政策给我链接: HTTP:// office.microsoft.com/en-us/access-help/using-multivalued-fields-in-queries-HA010149297.aspx#BM4.6 HTTP://www.mikesdotnetting .COM /条/ 123 / Storing-Files-and-Images-in-Access-with-ASP.NET 的 http://www.sitepoint.com/forums/showthread.php?t=666928 的 http://www.eggheadcafe.com/software/aspnet/35103540/multivalued-fields-in-access-2007-with-c-ado.aspx HTTP:/ /stackoverflow.com/questions/779211/programmatically-managing-microsoft-access-attachment-typed-field-with-c-net 感谢您帮助球员。推荐答案您可以使用OLE对象字段,它是VARBINARY(最大值)投其所好的最佳选择。You can use an OLE Object field, it is the best choice for varbinary(max) match up.一些注意事项:''Reference: Microsoft ActiveX Data Object x.x LibraryDim strSQL As StringDim strCN As StringDim rs As dao.RecordsetDim mstream As ADODB.StreamstrSQL = "SELECT Pix FROM Table1"Set rs = CurrentDb.OpenRecordset(strSQL)Set mstream = New ADODB.Streammstream.Type = adTypeBinarymstream.Openmstream.LoadFromFile "c:\docs\project.jpg" ''FileName & FullPathrs.AddNewrs.Fields("Pix").Value = mstream.Readrs.Updaters.Close修改要复制回磁盘,可以再次使用流:To copy back to disk, you can again use the Stream:Dim strSQL As StringDim cn As New ADODB.ConnectionDim mstream As New ADODB.StreamstrSQL = "SELECT Pix FROM Table1"Set rs = CurrentDb.OpenRecordset(strSQL)mstream.Type = adTypeBinarymstream.Openmstream.Write rs!Pixmstream.SaveToFile "c:\docs\pixout.jpg", adSaveCreateOverWrite 这篇关于存储字节] Access 2010中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-16 07:30