locked
db.GetLastInsertId().ToString(); RRS feed

  • Question

  • User1519602350 posted

    Below script is working ifne. But db.GetLastInsertId().ToString(); is not working. So whenever i upload the image it saving with out the id name.

     dbs.Execute(@"INSERT INTO HomeMainPageSlider (Description, FileTitle, FileExtension, ContentType, FileSize, UploadDate, FileContents, ImageURL,thumb, image, Heading, TagLine) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11)", "", fileTitle, fileExtension,
                    fileUpload.ImageFormat, fileBytes.Length, DateTime.Now, fileBytes,ImageURL,ImageURL, image, Heading, TagLine);
                    
     
                    var Id = db.GetLastInsertId().ToString();
     
                    
                    // Save main product image
                    var savePath = @"~\images\" + Id;
                    fileUpload.Save(filePath: savePath + ".png", 
                                        imageFormat: "png",
                                        forceCorrectExtension: true );
                    
                    // Resize and save thumbnail
                    fileUpload.Resize(height: 120, width: 120, 
                                        preserveAspectRatio: true);
                    fileUpload.Save(filePath: savePath + "_thumb.png", 
                                        imageFormat: "png",
                                        forceCorrectExtension: true );
                                         
     
                

    Friday, July 26, 2013 8:33 AM

Answers

  • User-1980594115 posted

    Your Id column must be the primary key, Identity, and Auto Increments.  Using Id = db.GetLastInsertId(); then should work.  Try not using .ToString with db.GetLastInsertId().  You can convert the integer to a string later:  var IdStr = Id.ToString();

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 26, 2013 9:32 AM

All replies

  • User-1980594115 posted

    Your Id column must be the primary key, Identity, and Auto Increments.  Using Id = db.GetLastInsertId(); then should work.  Try not using .ToString with db.GetLastInsertId().  You can convert the integer to a string later:  var IdStr = Id.ToString();

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 26, 2013 9:32 AM
  • User-1454326058 posted

    Hi ssvikramuk,

    Since we haven't heard from you for a long time, I temporarily close this case. I mark useful reply as answer. If you have any concerns, please free feel to reopen it or submit a new question. Thanks for your understanding.

    Thanks

    Best Regards

    Monday, August 5, 2013 8:16 AM