Parameters.Add(new SqlParameter(., (object) this.EndDate)) įrom my earlier trip to the database, I knew that the entry creation date was stored as datetime2(3) format:ĭatetime2 is available since SQL Server 2008 and is a far superior type than its predecessor datetime as it allows for a larger range of values and higher precision. Parameters.Add(new SqlParameter(., (object) this.StartDate)) Parameters.Add(new SqlParameter(., (object) this.FormDefinitionId))
While rummaging through the .Commands.FormDataDelete class, the SetParameters method piqued my interest: protected override void SetParameters(SqlParameterCollection parameters) So I fired up dotPeek again and dived deeper. for one of the three entries I had in the database. After some head-scratching, I removed one tick from the startDate, and guess what - it worked. I added some logging to check if the date and form ID were correct and it seemed that they were.
Ran the code again, but nothing was deleted from the database. I used the DateTime.AddTicks method on the endDate parameter to create the smallest possible range. Unfortunately, Sitecore developers were sneakier and I got the following message: EndDate must be after StartDate.īummer. I wanted to be sneaky and used the same date as both the startDate and endDate parameters. I checked the stored procedure using SQL Server Management Studio and saw that the date is compared using greater-or-equal and less-or-equal operators. If you're working on a real project, I would suggest going the first way as it is a much cleaner solution.Īfter processing the data, I called the SqlFormDataProvider.DeleteEntries and hoped for the best.