DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   Not able to display all image from DB except 1st image. (http://www.daniweb.com/forums/thread165918.html)

Makjain Jan 4th, 2009 2:30 am
Not able to display all image from DB except 1st image.
 
On the selection of value from dropdownlist, image is displayed in display page. Selectedvalue has many image in DB say 50+ but as per my query below it reads only 1st image of DB i.e.1st image of database. So do let me know where my code is gng wrong.

CODE VIEW OF DISPLAY PAGE:
public string FormatURL(object strArgument)
    {
        return ("Read.aspx?Coins=" + strArgument);
    }


SOURCE VIEW OF DISPLAY PAGE:
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"> 
<ItemTemplate>

Image:<asp:Image ID="Image1" runat="server" Height="50px" Width="100px" imageUrl='<%#FormatURL(DataBinder.Eval(Container.DataItem, "coins")) %>'/>

</ItemTemplate>

</asp:DataList>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CoinsString %>"

SelectCommand="SELECT [imgdata], [imgtype], [Coins] FROM [TABLE] WHERE ([Coins] = @Coins)">

<SelectParameters>

<asp:ControlParameter ControlID="DropDownList1" Name="Coins" PropertyName="SelectedValue" Type="String" />

</SelectParameters>

</asp:SqlDataSource>


CODE VIEW OF READ PAGE:
protected void Page_Load(object sender, EventArgs e)
    {
        string strImageID = Request.QueryString[0];
        SqlConnection cn = new SqlConnection("Data Source=MAKJAIN;Initial Catalog=DATABASE;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("select imgtype,imgdata from TABLE where coins='" + strImageID + "' ", cn);
        //
        try
        {
            cn.Open();
            SqlDataReader dr;
            dr = cmd.ExecuteReader();
            while (dr.Read())
            //yup we found our image
            {
                //retrving the image content type               
                Response.ContentType = dr["imgtype"].ToString();
                //displaying the image               
                Response.BinaryWrite((byte[])dr["imgdata"]);
            }
            cn.Close();
        }
        catch
        {
        }


All times are GMT -4. The time now is 11:13 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC