C#在DataList中显示MySQL数据库中的图像

时间:2016-05-16 16:10:21

标签: c# mysql asp.net

我遇到了问题,我正在尝试将存储在MySQL数据库中的图像显示为BLOB。问题是,当我添加代码以从数据库中检索数据时,会显示所有详细信息,但图像字段为空。

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();


                }

            }
        }

。 应根据从数据库中检索的ID显示图像。

0 个答案:

没有答案