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

问题描述

hiii全部
我有数据库,可以根据特定的用户或员工从数据库中提取一些图像.
现在,我尝试了一个代码,但是它只保留了最后一张图像.
我想问问是否有人可以帮助我根据特定用户重新整理所有图像并显示这些图像??

有什么建议......

谢谢

hiii all
i have database which i retieve from it some images according to specific user or employee.
now, i tried a code , but it retieve the last image only.
i want to ask if anyone can help me in retieving all images according a specific user and displa these images???

any suggestions......

thanks

推荐答案

public class ShowImage : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        Int32 empno;

        if (context.Request.QueryString["itemid"] != null)

            empno = Convert.ToInt32(context.Request.QueryString["itemid"]);

        else

            throw new ArgumentException("No parameter specified");



        context.Response.ContentType = "image/jpeg";

        Stream strm = ShowEmpImage(empno);

        byte[] buffer = new byte[4096];

        int byteSeq = strm.Read(buffer, 0, 4096);



        while (byteSeq > 0)
        {

            context.Response.OutputStream.Write(buffer, 0, byteSeq);

            byteSeq = strm.Read(buffer, 0, 4096);

        }

        //context.Response.BinaryWrite(buffer);
    }

    public Stream ShowEmpImage(int empno)
    {

        string conn = ConfigurationManager.ConnectionStrings["sWebCon"].ConnectionString;

        SqlConnection connection = new SqlConnection(conn);

        string sql = "SELECT empimg FROM tbl_Itemimages WHERE itemid = @itemid";

        SqlCommand cmd = new SqlCommand(sql, connection);

        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@itemid", empno);

        connection.Open();

        object img = cmd.ExecuteScalar();

        try
        {

            return new MemoryStream((byte[])img);

        }

        catch
        {

            return null;

        }

        finally
        {

            connection.Close();

        }

    }



谢谢



thanks


<img alt="" src="ImageFromDb.ashx?RowId=1" />


<img alt="" src="ImageFromDb.ashx?RowId=2" />


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p style="margin-left: 160px">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

                DataKeyNames="inum" DataSourceID="SqlDataSource1" CellPadding="4"

                ForeColor="#333333" GridLines="None">
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <Columns>
                    <asp:BoundField DataField="inum" HeaderText="inum" InsertVisible="False" ReadOnly="True"

                        SortExpression="inum" />
                    <asp:BoundField DataField="iname" HeaderText="iname" SortExpression="iname" />
                    <asp:TemplateField HeaderText="image">
                    <ItemTemplate>

<asp:image ID="image1" runat="server"

ImageUrl='<%# "Handler.ashx?inum=" + Eval("inum")%>'/>
</ItemTemplate>
</asp:TemplateField>

                </Columns>
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:GridView>

            <asp:SqlDataSource ID="SqlDataSource1" runat="server"

                ConnectionString="<%


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

08-23 23:07