如何从sql server的sql数据库中将图像加载到A Image控件中? 图像以图像格式存储... 图像控制在转发器中 转发器中的代码
<table id="tableposts" style="text-align: center; width: 100%; height: 80%;">
<tr>
<td>
<asp:LinkButton ID="lbpostusername" runat="server"
Text='<%#Eval("UserName") %>'>
</asp:LinkButton>
</td>
</tr>
<tr>
<td>
<asp:Label ID="posthead" runat="server"
Text='<%#Eval("PostHead") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<p id="postcontent"><%#Eval("PostContent") %></p>
</td>
</tr>
<tr>
<td>
<asp:Image ID="postimage" runat="server" ImageUrl=""/>
</td>
</tr>
</table>
检索值的代码
private DataSet GetData()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LoginConString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("Select PostID,UserName,PostHead,PostContent,PostImage from Posts WHERE USERID ='" + Session["New"].ToString() + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
postids = ds.Tables[0].Rows[0].ToString();
return ds;
}
答案 0 :(得分:0)
尝试这个
public string GetImageFromByte(object byt)
{
byte[] byts = (byte[])byt;
return byteArrayToImage(byts);
}
而不是
public string GetImageFromByte(object byt)
{
byte[] byts = Convert.ToByte(byt);
return byteArrayToImage(byts);
}