日期:2014-05-19  浏览次数:21045 次

(c#.net)如何把图片存储带数据库里,以后可以在库里调用显示出来?
2个内容,简单说明一下,谢谢!

------解决方案--------------------
保存图片:

OleDbConnection mycnn=new OleDbConnection( "provider=Microsoft.jet.oledb.4.0;data source=f:\\dazhu.mdb ");
mycnn.Open();

OleDbCommand mycmd=new OleDbCommand( "update info set picture=@a ",mycnn );

FileStream mystream=new FileStream( "f:\\1.jpg ",FileMode.Open,FileAccess.Read);
long len=mystream.Length;

mycmd.Parameters.Add( "@a ",OleDbType.Binary,(int)len, "picture ");
mycmd.Parameters[ "@a "].Direction=System.Data.ParameterDirection.Input;

byte []box=new byte[len];
mystream.Read(box,0,(int)len);

mycmd.Parameters[ "@a "].Value=box;

//更新
mycmd.ExecuteNonQuery();
MessageBox.Show( "ok ");
mystream.Close();
mycnn.Close();