为什么完整的图像路径没有存储在数据库中? [英] Why the full image path is not stored in the database?

查看:70
本文介绍了为什么完整的图像路径没有存储在数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我使用linq来存储sql并从数据库中检索图像,我使用varchar(max)数据类型。

这是我保存图像的代码,



 EventBL r =  new  EventBL(); 
r.Banner_SignUp_Page = System.IO.Path.GetFullPath(fuBanner.FileName);
r.Insert();





这里是为了追溯它。



  var  result1 = 来自 a  in  db.EMR_INVITATIONs 
join b in db.EMR_EVENTs on a。 EventID等于b.EventID
其中 b.EventID ==( int )会话[ eventid]


选择 new
{
Banner = b.Banner_SignUp_Page,
};

var ev = result1.First();

Image1.ImageUrl = ev.Banner;







但是在数据库中我发现整个图像路径都没有存储。

在数据库中存储了一些路径,我无法从数据库中检索图像

如果我的代码中有解决方案或改进

那么请让我知道,

谢谢你。

解决方案

你必须让我们知道究竟是什么内容 fuBanner.FileName 是。

它是磁盘上图像的完全指定文件路径吗?

是否可以是一个相对的URL?



在前一种情况下,您必须检查 System.IO.Path.GetFullPath(fuBanner.FileName) 返回。

在后一种情况下,您需要找到文件系统中文件的路径:



 mappedPath = HttpContext.Current.Server.MapPath(fuBanner.FileName); 





问候,

- Manfred

你应该在这个代码块之后调用db.submitchanges()事件



 EventBL r = < span class =code-keyword> new  EventBL(); 
r.Banner_SignUp_Page = System.IO.Path.GetFullPath(fuBanner.FileName);
r.Insert();
db.submitchanges();


不需要只在应用程序中创建文件夹来保存图像并从那里获取完整图像/>
和完整路径也在那里


Hey i use linq to sql for store and retrive image from database ,i use varchar(max) datatype for it.
Here is my code for save image,

EventBL r = new EventBL();
 r.Banner_SignUp_Page = System.IO.Path.GetFullPath(fuBanner.FileName);
 r.Insert();



and here is for retrive it.

var result1 = from a in db.EMR_INVITATIONs
 join b in db.EMR_EVENTs on a.EventID equals b.EventID
 where b.EventID == (int)Session["eventid"]


 select new
 {
 Banner = b.Banner_SignUp_Page,
 };

 var ev = result1.First();

 Image1.ImageUrl = ev.Banner;




but in database i found that whole path of image isn't store .
in database some of the path is stored,and i can't retrive image from database
If there is solution or improvement in my code
Then please let me know,
Thanks in advaance.

解决方案

You'd have to let us know what exactly the content of fuBanner.FileName is.
Is it a fully specified file path to an image on your disk?
Is it may be a relative URL?

In the former case you'd have to check what System.IO.Path.GetFullPath(fuBanner.FileName) returns.
In the latter case you'd need to find out the file's path in the filesystem:

mappedPath = HttpContext.Current.Server.MapPath(fuBanner.FileName);



Regards,

— Manfred


You should call db.submitchanges() event after this code block

EventBL r = new EventBL();
 r.Banner_SignUp_Page = System.IO.Path.GetFullPath(fuBanner.FileName);
 r.Insert();
db.submitchanges();


not need to do it just make folder in your application to save image and get full image from there
and full path is also there


这篇关于为什么完整的图像路径没有存储在数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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