[英]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.