【发布时间】:2017-07-02 03:57:44
【问题描述】:
我有一个页面可以将图像上传到 SQL Server 中的图像列,并将其转换为二进制...在另一个页面上,我想检索图像。我正在尝试在列表视图中这样做:
<ItemTemplate>
<tr style="">
<td>
<img src='data:image/jpg;base64,<%# Eval("Image") %>' />
</td>
<td>
<asp:Label ID="ImageDescLabel" runat="server" Text='<%# Eval("ImageDesc") %>' />
</td>
</tr>
</ItemTemplate>
我做错了吗?我认为这将是解决此问题的最佳方法。
图像保存代码如下所示:
void InsertImage()
{
byte[] theFile = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile file = FileUpload1.PostedFile;
file.InputStream.Read(theFile, 0, (int)FileUpload1.PostedFile.ContentLength);
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
int result = new _Image()
{
ImageName = txtFileName.Text,
ImageFile = theFile,
ImageDesc = txtDescription.Text
}.AddImage();
txtFileName.Text = "";
txtDescription.Text = "";
}
}
【问题讨论】:
-
真正重要的是 ado.net 操作代码。
-
@LeiYang 我不确定我明白你的意思。
-
没有一行相关代码怎么谈数据库?
-
还需要什么其他代码?我会发布它。我需要将 SQL Server 中的图像数据类型转换为列表视图中的图像。我已经看到人们在哪里使用 data:image/jpg;base64, + 二进制数据,所以我的问题是,如果这是从 Image 列中检索二进制数据,为什么它的工作方式不同,我是否遗漏了什么src= 部分?