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 January 21st, 2010, 02:02 PM
Authorized User
 
Join Date: Feb 2009
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add Keyword Field

Using the Title fields as my gudie, I have added a keyword field to my database and can use the admin/AddEditArticle.aspx page to add keywords to my content pages. I can also view the page on the ShowArticle.aspx and admin/ManageArticles.apsx pages.

However, when I try to load the BrowseArticles.aspx page the ArticlesProvider.cs throws the following exception;

Code:
Keywords 
 
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.IndexOutOfRangeException: Keywords
 
Source Error: 
 
Line 106:        protected virtual ArticleDetails GetArticleFromReader(IDataReader reader, bool readBody)
Line 107:        {
Line 108:            ArticleDetails article = new ArticleDetails(
Line 109:               (int)reader["ArticleID"],
Line 110:               (DateTime)reader["AddedDate"],
Source File: ...\App_Code\DAL\ArticlesProvider.cs    Line: 108 
Once this is sorted I would like to use content='<%# Eval("Keywords") %> in a keyword metatag for SEO purposes.
Please advise.
 
Old January 21st, 2010, 02:27 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You haven't posted the entire method, so it's hard to say what the problem is.

However, I suspect that the reader your are passing in as an argument has no "Keywords" field in it.

So, when you try something like reader["Keywords"], the runtime sees that the index "Keywords" is not in the range of existing reader indexes, which would throw an IndexOutOfRangeException.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old January 21st, 2010, 02:41 PM
Authorized User
 
Join Date: Feb 2009
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe the method that I needed to alter is;
Code:
protected virtual ArticleDetails GetArticleFromReader(IDataReader reader, bool readBody)
{
ArticleDetails article = newArticleDetails(
(int)reader["ArticleID"],
(DateTime)reader["AddedDate"],
reader["AddedBy"].ToString(),
(int)reader["CategoryID"],
reader["CategoryTitle"].ToString(),
reader["Title"].ToString(),
reader["Keywords"].ToString(),
reader["Abstract"].ToString(),
null,
reader["Country"].ToString(),
reader["State"].ToString(),
reader["City"].ToString(),
(reader["ReleaseDate"] == DBNull.Value ? DateTime.Now : (DateTime)reader["ReleaseDate"]),
(reader["ExpireDate"] == DBNull.Value ? DateTime.MaxValue : (DateTime)reader["ExpireDate"]),
(bool)reader["Approved"],
(bool)reader["Listed"],
(bool)reader["CommentsEnabled"],
(bool)reader["OnlyForMembers"],
(int)reader["ViewCount"],
(int)reader["Votes"],
(int)reader["TotalRating"]);
if (readBody)
article.Body = reader["Body"].ToString();
return article;
}
Does this suffice? I added reader["Keywords"].ToString(),
 
Old January 21st, 2010, 03:41 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

I don't know. Why don't you tell us if it works?
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old January 21st, 2010, 03:55 PM
Authorized User
 
Join Date: Feb 2009
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I should have mentioned ... that is the code that is presently throwing the exception.

Solved my problem, I neglected to change the GetPublishedArticlesByCategory stored procedure!

How do I go about retrieving the keyword content from the database?

... I've discovered that System.Web.UI.HtmlControls permits me to add the meta tag as illustrated below.
Code:
HtmlMeta meta = newHtmlMeta();
meta.Name = "keywords";
meta.Content = article.Keywords;
this.Header.Controls.Add(meta);
I'll use this approach to take the title and abstract fields and create title and description meta tags.

I remain open to better/improved suggestions.

Last edited by iguta; January 21st, 2010 at 04:30 PM.. Reason: Solved my problem. Yet again...





Similar Threads
Thread Thread Starter Forum Replies Last Post
If field not present then add spaces and concat pixelheart XSLT 14 June 5th, 2008 02:13 AM
add a new row when cursor comes to the last field bullsb Classic ASP Professional 8 March 11th, 2007 04:11 PM
add a new row when cursor comes to the last field bullsb Javascript How-To 2 February 26th, 2007 11:26 PM
How do I add keyword to the javascripted url? gilgalbiblewheel Javascript How-To 2 January 6th, 2006 12:13 PM
Add field to top of recordset vertigo Beginning VB 6 6 July 14th, 2004 03:24 AM





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