存储字节] Access 2010中 [英] Store Byte[] in 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.
的如果有人知道的方式来报道我的字节[](或图像)插入到数据库中再次把它弄出来,请让我知道!
请鸵鸟政策给我链接:
< A HREF =http://office.microsoft.com/en-us/access-help/using-multivalued-fields-in-queries-HA010149297.aspx#BM4.6相对=nofollow> 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
感谢您帮助球员。
推荐答案
您可以使用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 Library
Dim strSQL As String
Dim strCN As String
Dim rs As dao.Recordset
Dim mstream As ADODB.Stream
strSQL = "SELECT Pix FROM Table1"
Set rs = CurrentDb.OpenRecordset(strSQL)
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.LoadFromFile "c:\docs\project.jpg" ''FileName & FullPath
rs.AddNew
rs.Fields("Pix").Value = mstream.Read
rs.Update
rs.Close
修改
要复制回磁盘,可以再次使用流:
To copy back to disk, you can again use the Stream:
Dim strSQL As String
Dim cn As New ADODB.Connection
Dim mstream As New ADODB.Stream
strSQL = "SELECT Pix FROM Table1"
Set rs = CurrentDb.OpenRecordset(strSQL)
mstream.Type = adTypeBinary
mstream.Open
mstream.Write rs!Pix
mstream.SaveToFile "c:\docs\pixout.jpg", adSaveCreateOverWrite
这篇关于存储字节] Access 2010中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!