会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
My Program life
吴碧宇,Knightfire,Wubiyu,
Google Doc
博客园
首页
新随笔
联系
订阅
管理
从数据库中读取二进制数据,并显示图片
region 读取数据库中图片到内存.并显示
public
void
LoadToMemoryAndDisable(
string
serverAdress,
string
database)
{
//
读取数据库中图片到内存.并显示
SqlConnection conn
=
new
SqlConnection(
"
server=
"
+
serverAdress
+
"
;integrated security = sspi;database =
"
+
database);
SqlCommand cmd
=
new
SqlCommand(
"
select * from imgtable where imgname like '%bmp%'
"
, conn);
conn.Open();
SqlDataReader dr;
try
{
dr
=
cmd.ExecuteReader();
dr.Read();
System.Data.SqlTypes.SqlBinary sb
=
dr.GetSqlBinary(
2
);
//
或byte[] imageData = (byte[])dr[2];
MemoryStream ms
=
new
MemoryStream(sb.Value);
//
在内存中操作图片数据
Bitmap bmp
=
new
Bitmap(Bitmap.FromStream(ms));
this
.pictureBox1.Image
=
bmp;
dr.Close();
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
#endregion
posted @
2007-10-29 12:55
吴碧宇
阅读(
2672
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告