Not able to display all image from DB except 1st image.

Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Jan 2009
Posts: 1
Reputation: Makjain is an unknown quantity at this point 
Solved Threads: 0
Makjain Makjain is offline Offline
Newbie Poster

Not able to display all image from DB except 1st image.

 
0
  #1
Jan 4th, 2009
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:
  1. public string FormatURL(object strArgument)
  2. {
  3. return ("Read.aspx?Coins=" + strArgument);
  4. }


SOURCE VIEW OF DISPLAY PAGE:
  1. <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
  2. <ItemTemplate>
  3.  
  4. Image:<asp:Image ID="Image1" runat="server" Height="50px" Width="100px" imageUrl='<%#FormatURL(DataBinder.Eval(Container.DataItem, "coins")) %>'/>
  5.  
  6. </ItemTemplate>
  7.  
  8. </asp:DataList>
  9.  
  10. <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CoinsString %>"
  11.  
  12. SelectCommand="SELECT [imgdata], [imgtype], [Coins] FROM [TABLE] WHERE ([Coins] = @Coins)">
  13.  
  14. <SelectParameters>
  15.  
  16. <asp:ControlParameter ControlID="DropDownList1" Name="Coins" PropertyName="SelectedValue" Type="String" />
  17.  
  18. </SelectParameters>
  19.  
  20. </asp:SqlDataSource>


CODE VIEW OF READ PAGE:
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. string strImageID = Request.QueryString[0];
  4. SqlConnection cn = new SqlConnection("Data Source=MAKJAIN;Initial Catalog=DATABASE;Integrated Security=True");
  5. SqlCommand cmd = new SqlCommand("select imgtype,imgdata from TABLE where coins='" + strImageID + "' ", cn);
  6. //
  7. try
  8. {
  9. cn.Open();
  10. SqlDataReader dr;
  11. dr = cmd.ExecuteReader();
  12. while (dr.Read())
  13. //yup we found our image
  14. {
  15. //retrving the image content type
  16. Response.ContentType = dr["imgtype"].ToString();
  17. //displaying the image
  18. Response.BinaryWrite((byte[])dr["imgdata"]);
  19. }
  20. cn.Close();
  21. }
  22. catch
  23. {
  24. }
Last edited by peter_budo; Jan 11th, 2009 at 2:38 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC