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

VC#数据库(Access)编程有关问题

2011-12-28 
VC#数据库(Access)编程问题如何实现把pictureBox中的图片保存到Access数据库中呢,同样,怎么从Access库中读

VC#数据库(Access)编程问题
如何实现把pictureBox中的图片保存到Access数据库中呢,同样,怎么从Access库中读取出来,显示到pictureBox

谢谢

[解决办法]
参考:

//将图象存到数据库
void AddImageRow(DataTable tbl, string name, string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
DataRow row = tbl.NewRow();
row[0] = name;
row[1] = br.ReadBytes((int)br.BaseStream.Length);
tbl.Rows.Add(row);
br = null;
fs = null;

}
//从数据库中得到图象
public Image ImageFromBytes(DataTable tbl,int row)
{
Byte[] b =(Byte[] )( tbl.Rows[row][ "Img "]);
MemoryStream ms = new MemoryStream(b);
Image img = Image.FromStream(ms);
return img;

}

热点排行