如何在数据库中存储图像的路径以及如何检索图像并在网格视图中显示 [英] how to store path of image in data base and how to retrieve it and shows in grid view

查看:112
本文介绍了如何在数据库中存储图像的路径以及如何检索图像并在网格视图中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想将图像的路径存储在数据库中,但是我的这段代码无法正常工作.这是我的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;


这篇关于如何在数据库中存储图像的路径以及如何检索图像并在网格视图中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆