0

I have a problem, I am trying to display an images which are stored in MySQL database as BLOB. The problem is that when I add the code to retrieve data from database, all details are displayed but the image field is empty.

ASP.NET

<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal">
        <ItemTemplate>
            <asp:Label ID="lblID" runat="server" Text='<%# Eval("Product_Name") %>' /><br /> <asp:Label ID="Label1" runat="server" Text='£' /><asp:Label ID="Label2" runat="server" Text='<%# Eval("CurrentPrice") %>' />
            <br />
            <asp:Image ID="Image1" runat="server" ImageUrl='<%#  Eval("Image1") %>' />
        </ItemTemplate>
    </asp:DataList>

C#

string constr = ConfigurationManager.ConnectionStrings["ConnA"].ConnectionString;
        using (MySqlConnection con = new MySqlConnection(constr))
        {
            using (MySqlCommand cmd = new MySqlCommand())
            {
                cmd.CommandText = "SELECT Product_ID, Product_Name, Image1, CurrentPrice  FROM itemdata WHERE Active='Yes'";
                cmd.Connection = con;
                using (MySqlDataAdapter sda = new MySqlDataAdapter(cmd))
                {
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    DataList1.DataSource = dt;
                    DataList1.DataBind();


                }

            }
        }

. The images should be displayed based on ID which is retrieved from the database.

Deru
  • 1
  • 1
  • `ImageUrl`, as stated in the [MSDN](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.image.imageurl(v=vs.110).aspx) *Gets or sets the URL that provides the path to an image to display in the Image control.* Your image is stored as a blob... – t0mm13b May 16 '16 at 16:28
  • Although not a duplicate, I think you will find a lot of the information here useful... http://stackoverflow.com/questions/21877/dynamically-rendering-aspimage-from-blob-entry-in-asp-net – dazedandconfused May 16 '16 at 16:50
  • The above link does not help me, if you have any more advice I would appreciate it. – Deru May 16 '16 at 19:32

0 Answers0