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

C#把图片存入到数据库中,从数据库中提取,数据库已经打开了,数据库中图片的类型为image型,该如何处理

2012-04-24 
C#把图片存入到数据库中,从数据库中提取,数据库已经打开了,数据库中图片的类型为image型string fullpath

C#把图片存入到数据库中,从数据库中提取,数据库已经打开了,数据库中图片的类型为image型
string fullpath = openFileDialog.FileName;//文件路径
  FileStream fs = new FileStream(fullpath, FileMode.Open);
  byte[] imagebytes = new byte[fs.Length];
  BinaryReader br = new BinaryReader(fs);
  imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));
  string strSql = string.Format("insert into Employee(photo) values(@ImageList)");
  SQLServer.SQLInquiry(strSql);
求高手,详细代码,接下来该如何处理

[解决办法]
//(byte[])row["thePhoto"]
MemoryStream memorystream = null;
Bitmap image = null;
private void convertPhoto(byte [] bs,string empID)
{
 if (bs != null)
 {
memorystream = new MemoryStream(bs);
memorystream.Write(bs, 0, bs.Length);
image = new Bitmap(memorystream);
 }
}

热点排行