手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#读取图像保存到数据库中(数据库保存图片)
c#读取图像保存到数据库中(数据库保存图片)
摘要:复制代码代码如下:注:MyTools.g_PhotoField为数据库表中的图象字段名称//将图片保存到数据库中if(this.picPho...

复制代码 代码如下:

注: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;

}

【c#读取图像保存到数据库中(数据库保存图片)】相关文章:

C#三种判断数据库中取出的字段值是否为空(NULL) 的方法

C#保存图片到数据库并读取显示图片的方法

c#数据库与TXT导入导出的实例

C#连接MySql数据库的方法

c#读取xml文件到datagridview实例

C# String Replace高效的实例方法

C#读写操作app.config中的数据应用介绍

读取图片像素的具体实例

C#缩略图多路径多格式保存的实例

C#反射在实际应用中的实例代码

精品推荐
分类导航