image控件写成流的形式存SQL
来源:互联网 发布:雷人电视剧知乎 编辑:程序博客网 时间:2024/06/10 16:34
...
byte[] content = ReadBitmap2ByteArray(fileName);
StoreBlob2DataBase(content);
...
protected static byte[] ReadBitmap2ByteArray(string fileName)
{
using(Bitmap image = new Bitmap(fileName))
{
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
return stream.ToArray();
}
}
protected static void StoreBlob2DataBase(byte[] content)
{
SqlConnection con = Connection;
con.Open();
try
{
// insert new entry into table
SqlCommand insert = new SqlCommand(
"insert into Images ([stream]) values (@image)",con);
SqlParameter imageParameter =
insert.Parameters.Add("@image", SqlDbType.Binary);
imageParameter.Value = content;
imageParameter.Size = content.Length;
insert.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
byte[] content = ReadBitmap2ByteArray(fileName);
StoreBlob2DataBase(content);
...
protected static byte[] ReadBitmap2ByteArray(string fileName)
{
using(Bitmap image = new Bitmap(fileName))
{
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
return stream.ToArray();
}
}
protected static void StoreBlob2DataBase(byte[] content)
{
SqlConnection con = Connection;
con.Open();
try
{
// insert new entry into table
SqlCommand insert = new SqlCommand(
"insert into Images ([stream]) values (@image)",con);
SqlParameter imageParameter =
insert.Parameters.Add("@image", SqlDbType.Binary);
imageParameter.Value = content;
imageParameter.Size = content.Length;
insert.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
- image控件写成流的形式存SQL
- 将a链接写成按钮的形式
- 将C# Web Service返回的图片以流的形式显示在Delphi中的Image控件
- 汇编中为什么将FFFFh写成0FFFFh的形式
- 把一个整数写成十六进制的形式(一)
- PHP数组在内存的形式
- 12321能被写成______种两个质数相加的形式
- 把字段的值用sql语句写成表头
- WPF image控件的使用
- Silverlight 的image 控件运用
- 有符号的整数-负数在内存的存放形式
- 有符号的整数-负数在内存的存放形式
- 有符号的整数-负数在内存的存放形式
- 获得一个数据在内存中存储的二进制形式
- 图片以字节数组的形式存到数据库
- 各类数据在内存中的存放形式的问题
- stl实现计数存对象,实现更高形式的抽象
- float 变量在内存当中的存放形式
- Gridview鼠标选定颜色和具体列颜色
- FRAMESET 元素 | frameSet 对象
- Gridview自定义分页
- win2000/xp/2003下完全卸载ORACLE
- C# 开机启动
- image控件写成流的形式存SQL
- MyEclipse_6.0.1GA_E3.3常用简介
- JSP 实现文件上传
- listbox基本用法
- SWT,打包发布SWT程序,转EXE一条龙过程记录 一Eclipse下安装SWT
- listbox移位
- Multiview和View
- Delphi 6 XML数据绑定
- 网络游戏给现实生活带来的影响