Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从数据库中获取特定图像?_C#_Asp.net_Sql Server_Image - Fatal编程技术网

C# 如何从数据库中获取特定图像?

C# 如何从数据库中获取特定图像?,c#,asp.net,sql-server,image,C#,Asp.net,Sql Server,Image,我在aspx页面上有这样一个图像控件 <asp:Image ID="Image1" runat="server" Height="64px" Width="64px" ImageUrl='<%# "SideImageHandler.ashx?ID=" + Eval("ID")%>'/> public void ProcessRequest(HttpContext context) { SqlConnection con

我在aspx页面上有这样一个图像控件

    <asp:Image ID="Image1" runat="server" Height="64px" Width="64px" 
     ImageUrl='<%# "SideImageHandler.ashx?ID=" + Eval("ID")%>'/>
    public void ProcessRequest(HttpContext context)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["GalleryConnectionString"].ConnectionString;

        // Create SQL Command 
        Utility.ImageID = 2;
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "SELECT  IMAGE FROM  Icon WHERE (ID ="+ Utility.ImageID+")";
        cmd.CommandType = System.Data.CommandType.Text;
        cmd.Connection = con;

        SqlParameter ImageID = new SqlParameter("@ID", System.Data.SqlDbType.Int);
        ImageID.Value = context.Request.QueryString["ID"];
        cmd.Parameters.Add(ImageID);
        con.Open();
        SqlDataReader dReader = cmd.ExecuteReader();
        dReader.Read();
        context.Response.BinaryWrite((byte[])dReader["IMAGE"]);
        dReader.Close();
        con.Close();
    }
但它并没有向我展示图像。怎么了


此外,我有一个下载按钮,当用户点击它的图像将被下载我是新的不知道我把什么代码下载按钮点击事件?请提前向我表示感谢

这只是样品。


这只是一个示例。


这只是一个示例。


这只是一个示例。


@shahroz我是否将utility.ImageID替换someId?@buddy ok您应该根据您的情况更改此示例。@shahroz我是否将utility.ImageID替换someId?@buddy ok您应该根据您的情况更改此示例。@shahroz我是否将utility.ImageID替换someId?@buddy ok您应该根据您的情况更改此示例。@shahroz我是否更改此示例将utility.ImageID替换为someId?@buddy好的,您应该根据自己的情况更改此示例。
  <asp:image id="Image1" imageUrl="SideImageHandler.ashx?ID=<someId>"/>
<httpHandlers>
  <add verb="*" path="img/*" type="SideImageHandler"/>
</httpHandlers>
  public void ProcessRequest (HttpContext context) 
    { 
          int ID;
          if (context.Request.QueryString["ID"] != null)
               ID= Convert.ToInt32(context.Request.QueryString["ID"]);
          else
            throw new ArgumentException("No parameter specified");

        byte[] imageData= ;//get the image data from the database using the employeeId Querystring
        Response.ContentType = "image/jpeg";
        Response.BinaryWrite(imageData);

    }