源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c#读取图像保存到数据库中(数据库保存图片)

  • 时间:2020-04-25 04:20 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c#读取图像保存到数据库中(数据库保存图片)
[u]复制代码[/u] 代码如下:
注: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;     }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部