如何在不使用通用处理程序或

如何在不使用通用处理程序或

本文介绍了如何在不使用通用处理程序或.ashx文件的情况下从数据库中检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Img.aspx.cs" Inherits="Img" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btnUpload" runat="server" onclick="btnUpload_Click"

            Text="Upload Image" />
        <br />
        <br />
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <br />
        <br />
        <asp:Button ID="btnRetrieve" runat="server" onclick="btnRetrieve_Click"

            Text="Retrieve Image" />
        <br />
        <br />
        <asp:Image ID="Image1" runat="server" />
        <br />
        <asp:GridView ID="GridView1" runat="server"

            onselectedindexchanged="GridView1_SelectedIndexChanged">
        </asp:GridView>
        <br />
    </div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </form>
</body>
</html>









这是编码插入图像。







This is the coding for inserting image.

protected void btnUpload_Click(object sender, EventArgs e)
    {

        FileUpload img = (FileUpload)FileUpload1;

        if (img.HasFile && img.PostedFile != null)
        {
            HttpPostedFile File = FileUpload1.PostedFile;
            byt = new Byte[File.ContentLength];
            File.InputStream.Read(byt, 0, File.ContentLength);
            SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=adventureworks;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into ImageStore values(@ID,@ImageContent)", con);
            cmd.Parameters.AddWithValue("@ID",TextBox1.Text);
            cmd.Parameters.AddWithValue("@ImageContent", byt);
            cmd.ExecuteNonQuery();
            con.Close();
        }
    } 



如何在不使用.ashx文件的情况下从数据库中检索图像。我希望通过gridview直接从数据库中检索所有这些图像。你能帮助我吗?


How shall i retrieve image from database without using .ashx file.I want directly retrieve all those images by gridview from database.Can you help me?

推荐答案




这篇关于如何在不使用通用处理程序或.ashx文件的情况下从数据库中检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:03