MemoryStream stream = new MemoryStream();
SqlConnection conn = new SqlConnection(@"server=.;database=Test;Integrated Security=SSPI;");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("select top 1 Picture from Image", conn);
byte[] photo = (byte[])cmd.ExecuteScalar();
stream.Write(photo, 0, photo.Length);
//这下面要怎么写
}
catch
{
return;
}
在web程序中我把数据库中的图像(二进制)读取出来,想在Image控件上显示,请问要如何写代码,
解决方案 »
- dll的问题
- 更换桌面背景不成功!
- 为什么我用c#编的记事本程序一运行就导致机子重启呀?急~~~~~~~~~~~~~~~~~~·
- 保存客户提交的webservice请求
- 全局变量问题
- 简单的问题:如何将一个窗体设为另一个窗体的子窗体
- 关于斑马打印机指令问题
- 如何在一个窗口中来修改另一个窗口中的控件的属性,请指教
- http代码类型比如象 404 not found page等的详细说明列表哪里可以找到?最好是中文,现在急用,找到马上结贴,谢谢
- 程序在启动后,发现已有同样的实例在运行,此时如何让这个已运行的实例窗口显示在桌面的最前端?(C#、COM Interop)
- WinForm ToolStripItemCollection动态加载自定义对象问题
- 本地添加系统用户
conn.Open();
SqlCommand cmd = new SqlCommand("select top 1 Picture from Image", conn);
byte[] photo = (byte[])cmd.ExecuteScalar();
stream.Write(photo, 0, photo.Length);
Image控件对象.Image = Image.FromStream(stream);
SqlConnection conn = new SqlConnection(@"server=.;database=Test;Integrated Security=SSPI;");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("select top 1 Picture from Image", conn);
HttpResponse.BinaryWrite((byte[])cmd.ExecuteScalar());
}
catch
{
}再设置你的Image控件Url为image.aspx
pic.aspx是另一页页,代码如下:
MemoryStream stream = new MemoryStream();
SqlConnection conn = new SqlConnection(@"server=.;database=Test;Integrated Security=SSPI;");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("select top 1 Picture from Image", conn);
byte[] photo = (byte[])cmd.ExecuteScalar();
Response.ContentType = "image/pjepg";
Response.OutputStream.Write(photo , 0, photo .Length);
Response.End(); }
catch
{
return;
}
错误 1
非静态的字段、方法或属性“System.Web.HttpResponse.BinaryWrite(byte[])”要求对象引用 F:\asp程序\保存上传图片\image.aspx.cs 23 13 F:\asp程序\保存上传图片\
http://www.cnblogs.com/wfyfngu/archive/2008/10/09/1307390.html
将HttpResponse改成Response就OK!!