Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Minor category admin .Text bug fix

You can test this yourself.  If you edit a post and want to clear all categories, the categories will not clear.  The reason is that the checklistbox values are passed as an int[] array to the data provider, but if they're cleared a null value is passed.  Then when the method executes, if that array value is null or its length = 0, the method exits.  The fix is to comment out the initial array value check and update the blog_InsertLinkCategoryList stored proc.


public bool SetEntryCategoryList(int PostID, int[] Categories)
{
//   if(Categories == null || Categories.Length == 0)
//   {
//    return false;
//   }

 string[] cats = new string[Categories.Length];
 for(int i = 0; i {
  cats[i] = Categories[i].ToString();
 }
 string catList = string.Join(",",cats);

 SqlParameter[] p =
 {
  SqlHelper.MakeInParam("@PostID",SqlDbType.Int,4,PostID),
  BlogIDParam,
  SqlHelper.MakeInParam("@CategoryList",SqlDbType.NVarChar,4000,catList)
 };
 return NonQueryBool("blog_InsertLinkCategoryList",p);

}

That change alone would enter an orphan record in blog_Links with a categoryID of 0 (when you enter a new record without any Category assignment), so we need to updated the blog_InsertLinkCategoryLlist stored procedure as well by testing for an empty value of @CategoryList.

if @CategoryList = '' begin

Delete From blog_Links where
 BlogID = @BlogID and PostID = @PostID and CategoryType = 1

end
else begin...

 

Comments (0) | Post RSS RSS comment feed

Posted on 10/13/2004 12:30:00 PM by Dave Burke
Categories:
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke