Wrox Programmer Forums
| 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 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
  #1 (permalink)  
Old January 15th, 2008, 02:24 PM
Authorized User
 
Join Date: Oct 2007
Location: Arlington, VA, USA.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default System.InvalidCastException; System.Reflection.Tar

1. I have the exactly problem: "System.InvalidCastException:Specified cast is not valid" after I had added more input fields in AddEditArticle page.
I did add fields before and had some problems with store procedures. After I had fixed the store procedures and then it have been worked fine.
This time, I can't fix it as I did last time. Then I found this http://p2p.wrox.com/topic.asp?TOPIC_ID=54996 here and I tried to put Convert.ToInt32(reader["ArticleID"]) in ArticlesProvider.cs; however, it won't work for my case.

The errors pop up when I click on "BrowseArticle" which has a control: ArticleListing.ascx.

Also, I had more error message:

Line 106: protected virtual ArticleDetails GetArticleFromReader(IDataReader reader, bool readBody)
Line 107: {
Line 108: ArticleDetails article = new ArticleDetails(
Line 109: Convert.ToInt32(reader["ArticleID"]),
Line 110: (DateTime)reader["AddedDate"],

[InvalidCastException: Specified cast is not valid.]
   WS.YourAdviceSite.DAL.ArticlesProvider.GetArticleF romReader(IDataReader reader, Boolean readBody) in e:\01_13\YA_Web\App_Code\DAL\ArticlesProvider.cs:1 08
   WS.YourAdviceSite.DAL.ArticlesProvider.GetArticleC ollectionFromReader(IDataReader reader, Boolean readBody) in e:\01_13\YA_Web\App_Code\DAL\ArticlesProvider.cs:1 57
   WS.YourAdviceSite.DAL.SqlClient.SqlArticlesProvide r.GetPublishedArticles(DateTime currentDate, Int32 pageIndex, Int32 pageSize) in e:\01_13\YA_Web\App_Code\DAL\SqlClient\SqlArticles Provider.cs:184
   WS.YourAdviceSite.BLL.Articles.Article.GetArticles (Boolean publishedOnly, Int32 startRowIndex, Int32 maximumRows) in e:\01_13\YA_Web\App_Code\BLL\Articles\Article.cs:4 66
   WS.YourAdviceSite.BLL.Articles.Article.GetArticles (Boolean publishedOnly, Int32 categoryID, Int32 startRowIndex, Int32 maximumRows) in e:\01_13\YA_Web\App_Code\BLL\Articles\Article.cs:4 87

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(Objec t target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +371
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +17
   System.Web.UI.WebControls.ObjectDataSourceView.Inv okeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +676
   System.Web.UI.WebControls.ObjectDataSourceView.Exe cuteSelect(DataSourceSelectArguments arguments) +2659
   System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +84
   System.Web.UI.WebControls.DataBoundControl.Perform Select() +153
   System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
   System.Web.UI.WebControls.GridView.DataBind() +23
   WS.YourAdviceSite.UI.Controls.ArticleListing.Page_ Load(Object sender, EventArgs e) in e:\01_13\YA_Web\Controls\ArticleListing.ascx.cs:14 4
   System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e) +31
   System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e) +68
   System.Web.UI.Control.OnLoad(EventArgs e) +88
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Control.LoadRecursive() +158
   System.Web.UI.Control.LoadRecursive() +158
   System.Web.UI.Control.LoadRecursive() +158
   System.Web.UI.Control.LoadRecursive() +158
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint

---------
2. Moremore, I tried Tara's solution:
http://p2p.wrox.com/topic.asp?TOPIC_...tem.Reflection

Using "if (reader.Read()) {...}". But it can't solve my problem neither.

-----------
PLEASE HELP IF YOU KNOW WHAT IS WRONG. THANK YOU VERY MUCH.



jophie
__________________
jophie
  #2 (permalink)  
Old January 16th, 2008, 01:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You might try this:

int.Parse(reader["ArticleID"].ToString())

  #3 (permalink)  
Old January 16th, 2008, 03:29 PM
Authorized User
 
Join Date: Oct 2007
Location: Arlington, VA, USA.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It won't work neither...

Other suggestions, please!

-j


Similar Threads
Thread Thread Starter Forum Replies Last Post
System.InvalidCastException: Specified cast is not scslarry BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 6 January 18th, 2007 07:34 PM
PhileIdentity - System.InvalidCastException terencetham BOOK: ASP.NET Website Programming Problem-Design-Solution 6 September 25th, 2006 02:27 PM
System.InvalidCastException: QueryInterface for sweta .NET Web Services 5 June 8th, 2006 02:32 AM
'System.InvalidCastException' Problem! Please help CyberGeek ADO.NET 0 March 19th, 2006 03:14 PM
System.InvalidCastException: Specified cast is not chiefg BOOK: ASP.NET Website Programming Problem-Design-Solution 2 March 2nd, 2004 01:29 PM





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