日期:2014-05-20  浏览次数:20751 次

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;

}