【问题标题】:Hot to display binary image from db to image box.?8热显示二进制图像从数据库到图像框。?8
【发布时间】:2014-12-12 18:56:25
【问题描述】:

我想在我的网页上显示学生信息和学生图像,同时从下拉列表中选择学生 ID。下面给出的代码用于显示信息和图像。但是图像显示不正确。请检查代码并输出屏幕。

代码:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

        DataSet1TableAdapters.TextBoxTableTableAdapter tx;
        tx = new DataSet1TableAdapters.TextBoxTableTableAdapter();
        DataTable dt = new DataTable();
        dt = tx.GetstudData(int.Parse(DropDownList1.SelectedValue));

        foreach (DataRow row in dt.Rows)
        {
            TextBox1.Text = (row["FirstName"].ToString());
            TextBox2.Text = (row["SecondName"].ToString());
            byte[] barrImg = (byte[])row["StudImage"];
            string base6=Convert.ToBase64String(barrImg);
            Image1.ImageUrl = "data:image/jpeg;base6," + base6;
        }
}

SQL 查询:

SELECT FirstName, SecondName, StudentImage FROM TextBoxTable WHERE (Id = @Id)

aspx来源:

<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" />
</div>

数据库:

输出:

【问题讨论】:

    标签: c# asp.net image binary


    【解决方案1】:

    base64 代替 base6 ???

    Image1.ImageUrl = "data:image/jpeg;base64," + base6;
    

    【讨论】:

      猜你喜欢
      • 2014-12-11
      • 1970-01-01
      • 1970-01-01
      • 2019-12-20
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-26
      相关资源
      最近更新 更多