我正在尝试将图像上传到我的网站,这很好用,但我也试图将该图像的文件名添加到数据库中。一切正常,除了将NULL值传递到数据库而不是文件名?
代码是:
@{
Layout = "~/_template1.cshtml";
var db = Database.Open("StayInFlorida");
//Get images
var imageget = "SELECT * FROM ImageInfo WHERE PropertyID='7'";
WebImage photo = null;
var newFileName = "";
var imagePath = "";
var imageThumbPath = "";
if(IsPost){
photo = WebImage.GetImageFromRequest();
if(photo != null)
{
newFileName = Guid.NewGuid().ToString() + "_" +
Path.GetFileName(photo.FileName);
imagePath = @"images\property\" + newFileName;
photo.Save(@"~\" + imagePath);
}
var imageput = "INSERT INTO ImageInfo (ImageURL) VALUES (@0)";
db.Execute(imageput, Request["newFileName"]);
}
}
答案 0 :(得分:1)
将db.Execute(imageput, Request["newFileName"]);
更改为db.Execute(imageput, newFileName);