Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 20th, 2009, 04:28 PM
Authorized User
 
Join Date: Feb 2009
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating Article Subcategories using ParentCategoryID

I need to implement multiple categories for articles. I followed the recommendation of adding a ParentCategoryID to the db using the int field type. I have changed the Category.cs, CategoryDetails.cs, and ArticlesProvider.cs files as needed and sucessfully built the solution. Upon running the site I receive the System.InvalidCastException detailed below;

Code:
protected virtual CategoryDetails GetCategoryFromReader(IDataReader reader)
     {
       return new CategoryDetails(
(int)reader["CategoryID"],
            (int)reader["ParentID"],
I must be overlooking something. Any help would be greatly appreciated.
Cheers

Last edited by iguta; May 20th, 2009 at 04:57 PM..
 
Old May 20th, 2009, 06:44 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Possibly a typo?

If you named your column ParentCategoryID as you stated, then reader["ParentID"] might be causing a problem.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old May 20th, 2009, 06:55 PM
Authorized User
 
Join Date: Feb 2009
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default No typo

I used ParentCategoryID to reference it's mention in the book.

I stepped away to clear my head and realized that my trial by fire must continue. I added the ParentID only to the CategoriesDB, and suspect I may need to do the same in the ArticlesDB.

... any counsel?
 
Old May 20th, 2009, 08:05 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by iguta View Post
I used ParentCategoryID to reference it's mention in the book.
Okay, it was worth a quick shot though.

I will tell you that an InvalidCastException at this point means that one of your objects (reader["CategoryID"] or reader["ParentID"]) cannot be cast to an Int32 for some reason.

What I would do, if I were having this problem, is to set a breakpoint and step into this method. When the exception is thrown, inspect those two objects in the debugger and see what their values are. Chances are one (or both) of them has a bad/unexpected value.

Let us know how you make out with it.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old May 20th, 2009, 09:55 PM
Authorized User
 
Join Date: Feb 2009
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default System.InvalidOperationException

I set a breakpoint and received a new error. I do not know how to see what the values are in the debugger. I see a treeview in a locals window with two options -- this and reader than both seem to endless drill down into info.

The copy of the new error message follows.

Code:
Invalid attempt to read when no data is present. 
 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
 
Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present.
 
Source Error: 
 
Line 78:         protected virtual CategoryDetails GetCategoryFromReader(IDataReader reader)Line 79:         {Line 80:             return new CategoryDetails(                Line 81:                (int)reader["CategoryID"],Line 82:                (int)reader["ParentID"],
 
Old May 22nd, 2009, 05:31 AM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default

Hi,
I am also working on sub-categories feature.
Both on logic and gui aspects.
I need to warn you that this is not trivial as it first seems.
It will involve modifying your DAL and BLL objects, and of course stored procedures.

Some of the issues are:

Hierarchical deletion, when a category is deleted all it's children need also to be deleted.
Moving category from one parent to another.

And don't forget the presentation (or even Hierarchical presentation) of categories listings, in other words the GUI.

As I've mentioned in the begining of my post I am also working on this feature, and to tell you the truth, was plaaning to open a new thread until i saw this one.

I want to show what I've done so far:
http://aspspider.info/yevis/categories.aspx
Of course by looking on this you can only see the gui part but if you have some questions please ask.

This is how i plan to make the categories module.

I was inspired by ww.sitefinity.com for making the "TreeGrid" design.
(Made it with multi nested repeaters that i create on run time)
It also has ajax ModalPopup control for displaying category delete confirmation and for poping up FormView with category's details.

Feel free to delete/modify/insert because it's all done in memory, (only the initaial reading done from a database).
All changes are stored and session so just reopen browser to reset. (I hope aspspider can take it :))

It works a little bit slow because it's not yet optimized and because it's sits on limited-free host.

Last edited by yevi; May 22nd, 2009 at 05:40 AM..
 
Old May 22nd, 2009, 05:37 AM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default

I'll need some help with optimizing and improving it (cause I am just learning).
So I plan to show full source code so you people can help me with it.

But first I need to make this code a little bit "programming standardized" , add comments, meaningful var names.

Because this is yet not part of BeerHouse Project, it's not implements BeerHouse's layer architecture. (BLL and DAL are together)

So i hope next week i will release the code.
 
Old May 22nd, 2009, 10:06 AM
Authorized User
 
Join Date: Feb 2009
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sub-categories feature

I like your efforts so far and look forward to the code you plan to release. Did you have to modify App_Code objects for the categories and articles, or just the categories alone?

As you may tell, I too am learning and if there is anything I can do to help you please let me know.

Cheers.
 
Old May 22nd, 2009, 11:08 AM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default

Every object and stored procedure that is related to categories needed to be modified.

Most of the modification are small.
 
Old June 1st, 2009, 12:29 PM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default

Here you go (Sorry for long time I was busy...)

http://www.adrive.com/public/7431eff...bcb532213.html
This includes the aspx and cs files of the subcategory page and css file.
(Note that this aspx is a content page)
I've aslo added the BLL and DAL files that i've altered.
And there is also a text files with stored procedures.

Again all this is not final release it's just what I am working on.









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.