locked
Error updating IMAGE columns RRS feed

  • Question

  • User1546138644 posted

    My current headache is about allowing the user to update an image attached to their record. The images are stored in the database in IMAGE datatype columns. Yes I know they are allegedly being deprecated and I will port the code to use other datatypes in due course, this is almost a prototyping exercise.

     

    In order to update the correct columns I use the following function:

     

    public static bool UpdateBandImage(string bandId, WebImage bandImage)
    {
        var db = Database.Open((string)App.db);
    
        // Resize for the main image
        bandImage.Resize(height: 400, width: 400, preserveAspectRatio: true, preventEnlarge: true);
    
        byte[] imageMain=bandImage.GetBytes();
    
        string SQLUpdate = "update ls_band_images set imageMain=@1 where ownerId=@0)";
    
        int imageRecords = db.Execute(SQLUpdate,
                                        bandId,
                                        imageMain
                                        ); 
    
        return (imageRecords>=1) ? true:false;
    }
    

     

    I know that 'bandId' is being populated with the correct value and I know that 'bandImage' is a non-null image uploaded from a form. This is almost exactly the same logic I use to create the records in the first place and that works well with no issues.

    But when I run this the SQL throws an exception:

    [SqlCeException (0x80004005): There was an error parsing the query. [ Token line number = 1,Token line offset = 56,Token in error = ) ]]
       System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr) +48
       System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan() +700
       System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options) +542
       System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery() +21
       WebMatrix.Data.Database.Execute(String commandText, Object[] args) +116
       ASP.LSBandFunctions.UpdateBandImage(String bandId, WebImage bandImage) +384
       ASP._Page_Bands_updateBand_cshtml.Execute() in c:\Users\Marvey\Documents\My Web Sites\EmptySite2\Bands\updateBand.cshtml:68
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
       System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +69
       System.Web.WebPages.WebPage.ExecutePageHierarchy() +151
       System.Web.WebPages.StartPage.RunPage() +17
       System.Web.WebPages.StartPage.ExecutePageHierarchy() +62
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
       System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +114
    
      
    
    

    I've looked for the meaning of the excpetion code but I cannot find any usable information that seems relevant to this issue. I am beginning to wonder if it is not possible to update the values of IMAGE columns...

    Anyone have any ideas?

     

     

     

     

     

    Monday, July 22, 2013 6:17 PM

Answers

  • User1546138644 posted

    Doh! I have literally seen my error in the 5 seconds after posting here! All sorted... I had included a spurious ')'

     I can't find a way of deleting my post

    Sorry to bother you all Cool

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 22, 2013 6:20 PM

All replies

  • User1546138644 posted

    Doh! I have literally seen my error in the 5 seconds after posting here! All sorted... I had included a spurious ')'

     I can't find a way of deleting my post

    Sorry to bother you all Cool

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 22, 2013 6:20 PM
  • User-821857111 posted

    The images are stored in the database in IMAGE datatype columns. Yes I know they are allegedly being deprecated

    They are deprecated in SQL Server, not SQL CE. You are using the correct data type for your database.

    Tuesday, July 23, 2013 3:15 AM