title: Webmatrix - Image upload and post to DB
body: <p>I am trying to upload an image to my site, which works fine, but i am also trying to add the filename of that image to the database. Everything works, except a NULL value is passed into the database instead of the filename?</p>
  
  <p>Code is :</p>
  
  <pre><code>@{  
  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"]);
  }
  }
  </code></pre>