Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 21st, 2010, 02:02 PM
Authorized User
Points: 76, Level: 1
Points: 76, Level: 1 Points: 76, Level: 1 Points: 76, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
  #2 (permalink)  
Old January 21st, 2010, 02:27 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
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(); 
}
  #3 (permalink)  
Old January 21st, 2010, 02:41 PM
Authorized User
Points: 76, Level: 1
Points: 76, Level: 1 Points: 76, Level: 1 Points: 76, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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(),
  #4 (permalink)  
Old January 21st, 2010, 03:41 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
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(); 
}
  #5 (permalink)  
Old January 21st, 2010, 03:55 PM
Authorized User
Points: 76, Level: 1
Points: 76, Level: 1 Points: 76, Level: 1 Points: 76, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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...
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:39 PM.


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