如何在数据库中存储图像的路径以及如何检索图像并在网格视图中显示
问题描述:
我想将图像的路径存储在数据库中,但是我的这段代码无法正常工作.这是我的aspx.cs文件代码......
i want to store the path of image in data base but my this code is not working properly. here is my aspx.cs file code ......
string path ="@~/users_images/" + File1.PostedFile.FileName;
File1.PostedFile.SaveAs(Server.MapPath(path));
objbll.Images = File1.PostedFile.FileName;
这是bll代码....
and here is the bll code ....
public string Images
{
get { return images; }
set { images = value; }
}
param[11] = new SqlParameter("@images", SqlDbType.NVarChar);
param[11].Value = Images;
这是default.aspx代码文件......
and here is default.aspx code file ......
<asp:GridView ID="grd_profile" runat="server" AutoGenerateColumns="False" Height="324px"
Width="428px" style="margin-right: 0px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table style="width:100%;">
<tr>
<td style="width:100px;">
<img height="200px" src = "<%#Eval("images")%>" width="200px" alt = ""/>
</td>
<pre>
答
以下是工作示例供您参考:
http://www.aspdotnet-suresh.com/2011/03/how-to-save-images-into-folder-and.html [
Here is the working example for your reference:
http://www.aspdotnet-suresh.com/2011/03/how-to-save-images-into-folder-and.html[^]
您在这里犯的错误是您的BLL您存储客户端文件路径的代码.
您的代码应该像这样
The mistake you are doing here is in your BLL code you are storing the client''s file path.
Your code should go something like this
string serverFilePath = Server.MapPath("@~/users_images/" + File1.PostedFile.FileName);
File1.SaveAs(serverFilePath);
objbll.Images = serverFilePath;