从数据库中检索图像并在图像控件中显示 [英] Retrieve Image from Database and display in Image control

查看:70
本文介绍了从数据库中检索图像并在图像控件中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想在我的图像控制中显示图像



这是我的数据库表

I just want to display the Image in my Image Control

This is my Database Tables

CREATE TABLE Logo(
 id int,
 image varbinary(max),
 status char(1)
) 


INSERT INTO Logo(id,status, image)
SELECT '1', 'Y', *
FROM OPENROWSET(BULK N'E:\logo.jpg', SINGLE_BLOB) image; 

select image from Logo where id=1 and status='Y'





aspx.cs



aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        string constr = ConfigurationManager.ConnectionStrings["conn"].ToString();

        SqlConnection con = new SqlConnection(constr);
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "select image from Logo where id=1 and status='Y'";
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;

        SqlDataReader dr = cmd.ExecuteReader();
        dr.Read();
        
        Response.BinaryWrite((Byte[])dr[0]);
        con.Close();
        Response.End();
     }







Aspx Page




Aspx Page

<table >
<tr>
<td><asp:Image ID="logo" runat="server"/></td>
</tr>
</table >

推荐答案

您可以快速浏览以下链接以获取交叉参考。



http://www.dotnetgallery.com/kb/resource21-How-to-store-and-retrieve-images-from-SQL-server-database-using-aspnet.aspx [ ^ ]
You can quickly go through following link for the cross reference.

http://www.dotnetgallery.com/kb/resource21-How-to-store-and-retrieve-images-from-SQL-server-database-using-aspnet.aspx[^]


这篇关于从数据库中检索图像并在图像控件中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆