首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

急求解答!怎样读取access中的图片解决办法

2012-03-09 
急求解答!怎样读取access中的图片大家好,我用vb.net连接access数据库,读取一个表的中的字段,这个字段是图

急求解答!怎样读取access中的图片
大家好,我用vb.net连接access数据库,读取一个表的中的字段,这个字段是图片,但是一般图片应该是用路径表达,但是这个表里的图片却是“包”,我应该怎么读取,谢谢大家的帮助!!!

[解决办法]
转换成二进制流来读,例如:
private void ReadPicture(int ID)
{

string SQL = "SELECT Picture,FileSize,ContentType FROM table WHERE ID = " ID;//FileSize为图片大小,ContentType为图片格式

// Create Connection object
OleDbConnection dbConn = new OleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\home\data\Jaqua_Product.mdb ");

// Create Command Object
OleDbCommand dbComm = new OleDbCommand(SQL, dbConn);

// Open Connection
dbConn.Open();

// Execute command and receive DataReader
OleDbDataReader dbRead = dbComm.ExecuteReader();

dbRead.Read();

// Clear Response buffer
Response.Clear();

// Set ContentType to the ContentType of our file
// Response.ContentType = (string)dbRead[ "ContentType "];

// Write data out of database into Output Stream

Response.OutputStream.Write((byte[])dbRead[ "Picture "], 0, (int)dbRead[ "FileSize "]);

// Close database connection
dbConn.Close();

// End the page
Response.End();
}

把图片转换成二进制流.

热点排行