注:mytools.g_photofield为数据库表中的图象字段名称
//将图片保存到数据库中
if(this.picphoto.image==null)
{
m_datarow[mytools.g_photofield]=dbnull.value;
}
else
{
try
{
memorystream ms = new memorystream ();
picphoto.image.save (ms, system.drawing.imaging.imageformat.bmp);
byte [] mydata = new byte [ms.length ];
ms.position = 0;
ms.read (mydata,0,convert.toint32 (ms.length ));
m_datarow[mytools.g_photofield] = mydata;
}
catch(system.exception ee)
{
messagebox.show(ee.message);
}
}//else
//读取图象
if(this.m_datarow[mytools.g_photofield]!=dbnull.value)
{
try
{
byte[] byteblobdata = new byte[0];
byteblobdata = (byte[])m_datarow[mytools.g_photofield];
memorystream stmblobdata = new memorystream(byteblobdata);
this.picphoto.image= image.fromstream(stmblobdata);
}
catch(exception ex)
{
messagebox.show(ex.message);
}
}
else
{
this.picphoto.image= null;
}
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论