简体   繁体   English

使用文件路径asp.net和C#从数据库显示图像

[英]Show image from database using filepath asp.net and C#

I am trying to show image on the label retrieved from the database. 我试图在从数据库检索的标签上显示图像。 My front end code is 我的前端代码是

<asp:Image ID="Image1" runat="server" Height="150px" Width="120px" />

where as my backend code is: 我的后端代码在哪里:

  string query = "select quantity, name, price, description, type, Catagory, FilePath from product where p_id ='" + IdList.SelectedValue + "'  ";
            con.Open();
            SqlCommand cmd = new SqlCommand(query, con);
            SqlDataReader rdr = cmd.ExecuteReader();

            if(rdr.HasRows)
            {
                while (rdr.Read())
                {  string filename1 = rdr.GetString(6);
                    Image1.ImageUrl="C:\\Users\\Fatima\\Downloads\\db-final-project\\db final project\\db final project\\UploadedImages\\"+filename1; }

kindly help me in displaying my image in label in the web form 请帮助我在网络表单的标签中显示我的图像

" C:\\Users\\Fatima\\Downloads\\db-final-project\\db final project\\db final project\\UploadedImages\\ " is not a valid URL. C:\\ Users \\ Fatima \\ Downloads \\ db-final-project \\ db最终项目\\ db最终项目\\ UploadedImages \\ ”不是有效的URL。 Image1.ImageUrl expects a URL, like " http://www.SomeSite.com/someImage.jpg ", and not a local directory on your hard-drive. Image1.ImageUrl需要一个URL,例如“ http://www.SomeSite.com/someImage.jpg ”,而不是硬盘驱动器上的本地目录。

Put those pictures in your database (there should be a table column of type 'image' which can store images) or better yet - add it as an asset to your project and link to its relative path (eg, the path in which your site/application resides in, without the domain name). 将这些图片放在数据库中(应该有一个类型为“ image”的表列,可以存储图片)或更好-将其作为资产添加到您的项目中,并链接到其相对路径(例如,网站所在的路径) / application驻留在其中,没有域名)。

You can see a valid usage of Image.ImageUrl in here: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.image.imageurl.aspx 您可以在以下位置看到Image.ImageUrl的有效用法: https ://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.image.imageurl.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET C#从SQL Server数据库获取检索并显示图像 - ASP.NET C# Get retrieve and show image from SQL Server database 如何从SQL Server数据库中检索图像字段civilimage1,civilimage2,以在带有vb.net或c#的ASP.NET中使用图像控件进行显示? - How to retrieve image fields civilimage1,civilimage2 from SQL Server database to show using image control in ASP.NET with vb.net or c#? 如何使用C#显示asp.net中数据库中的数据 - how to show data from database in asp.net using c# 使用asp.net c#从文件夹到页面显示图像 - show image from folder to page using asp.net c# 如何在ASP.NET中使用C#从数据库中检索二进制图像 - How to retrieve binary image from database using C# in ASP.NET 如何使用c#从asp.net中的数据库绑定图像? - how to bind image from database in asp.net using c#? 使用asp.net gridview和c#从php myadmin数据库显示图像 - displaying image from php myadmin database using asp.net gridview and c# 使用asp.net,C#从数据库加载图像后调整图像大小 - Resizing an image after loading it from the database using asp.net, C# 使用C#和ASP.NET从Memorystream保存图像 - Save Image from Memorystream using C# and ASP.NET 如何在asp.net core razor中显示来自数据库文件路径的图像 - How to display image from database filepath in asp.net core razor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM