我正在尝试将图像上传到我的网站,效果很好,但我也在尝试将该图像的文件名添加到数据库中。一切正常,除了将 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"]);
}
}