table is not updated with image2 field. but image is stored in images folder. RRS feed

  • Question

  • User1493762548 posted

    here is code of image2.cshtml page i tried both var productId =urlData[0].AsInt( ); and var ProductId=Reques["Id"]; in first line after if condition.

    i think there is error in updateCommand  or db.Execute.

    addproducts.cshtml. redirect after insterting the record in products table  by the statement


    product table has columns like productname, Image1 Image2 ....etc.

        if (!WebSecurity.IsAuthenticated)
           var ProductId = Request["Id"];
           var width=320;
        var height=320;
        var Image2="";
        if(IsPost && Validation.IsValid()){
            //-----image code--
          var photo = WebImage.GetImageFromRequest();
            if(photo == null ){
                ModelState.AddFormError("please upload jpg image!");
            var FileExtension=Path.GetExtension(photo.FileName).Trim();
            if( FileExtension!=".JPEG"){  
                Validation.AddFormError("please upload jpeg image!");
                Image2 = Guid.NewGuid().ToString() + "_" +
               var Image2Path = @"Images\" + Image2;
                photo.Save(@"~\" + Image2Path);
                 var db = Database.Open("PhotoGallery");
                  var updateCommand = "UPDATE Products SET Image2=@0 where ProductId=@1";
                db.Execute(updateCommand, Image2,ProductId);
    <!DOCTYPE html>
    <html lang="en">
            <meta charset="utf-8" />
          <legend> Upload Image </legend>
          <label for="Image">Image</label>
          <input type="file" name="Image" />
          <input type="submit" value="Add picture" />
            <a href="~/"><button>Finish</button></a>
    Sunday, July 3, 2016 1:01 AM


  • User-821857111 posted

    If you are using the Href helper to generate the URL, the value should be available from UrData[0]. Double check the URL that the AddProducts page is redirecting to and ensure that the value obtained form db.GetLastInsertId is not null and is being passed correctly.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 6, 2016 8:24 AM