Last post Jul 23, 2013 03:15 AM by Mikesdotnetting
Jul 22, 2013 06:17 PM|Marv99|LINK
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);
string SQLUpdate = "update ls_band_images set imageMain=@1 where ownerId=@0)";
int imageRecords = db.Execute(SQLUpdate,
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.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options) +542
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.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +69
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?
Jul 22, 2013 06:20 PM|Marv99|LINK
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
Jul 23, 2013 03:15 AM|Mikesdotnetting|LINK
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.