Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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 May 28th, 2008, 04:15 AM
Registered User
 
Join Date: May 2008
Location: delhi, delhi, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to msinha199 Send a message via AIM to msinha199 Send a message via Yahoo to msinha199
Default invalisd cast

hey friends....i need your help

while compiling browsearticles.aspx from the downloaded code (TBH) i am facing a problem which is copied here

Source Error:


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


Source File: d:\final project\my website\App_Code\DAL\ArticlesProvider.cs Line: 107

Stack Trace:


[InvalidCastException: Specified cast is not valid.]
   MS.Institute4Idea.DAL.ArticlesProvider.GetArticleF romReader(IDataReader reader, Boolean readBody) in d:\final project\my website\App_Code\DAL\ArticlesProvider.cs:107
   MS.Institute4Idea.DAL.ArticlesProvider.GetArticleC ollectionFromReader(IDataReader reader, Boolean readBody) in d:\final project\my website\App_Code\DAL\ArticlesProvider.cs:146
   MS.Institute4Idea.DAL.SqlClient.SqlArticlesProvide r.GetPublishedArticles(DateTime currentDate, Int32 pageIndex, Int32 pageSize) in d:\final project\my website\App_Code\DAL\SqlClient\SqlArticlesProvider .cs:184
   MS.Institute4Idea.BLL.Articles.Article.GetArticles (Boolean publishedOnly, Int32 startRowIndex, Int32 maximumRows) in d:\final project\my website\App_Code\BLL\Articles\Article.cs:394
   MS.Institute4Idea.BLL.Articles.Article.GetArticles (Boolean publishedOnly, Int32 categoryID, Int32 startRowIndex, Int32 maximumRows) in d:\final project\my website\App_Code\BLL\Articles\Article.cs:415

i tried many things including
(reader["ArticleID"] == DBNull.Value ? 0 : (int)reader["ArticleID"]),
but nothing worked...i am totally trapped and gone out of my mind to understand this problem.

please suggest me possible solution and if not plz suggest possible problem so that i can start thinking process again






mahesh
  #2 (permalink)  
Old May 28th, 2008, 06:58 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there.. what data type is articleID?
Maybe you has to cast to something else?? or if you downloaded the code, maybe the DB datatype is wrong.

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
  #3 (permalink)  
Old May 28th, 2008, 07:01 AM
Registered User
 
Join Date: May 2008
Location: delhi, delhi, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to msinha199 Send a message via AIM to msinha199 Send a message via Yahoo to msinha199
Default

Hey thanks buddy for responding..

but i can not cast it on to other datatype i have checked everything

i have created a table in the SQL server 2005 and the ArticleID is of type INT with size 4

this is the problem



mahesh
  #4 (permalink)  
Old May 28th, 2008, 07:08 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Are you sure that the cast that you specify is the problem?? source line is 107, and is the cast for the object, maybe the problem is somewhere else???

Do you have an empty constructor?? if yes, try it, and pass any parameter one by one to see what field fails...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========


Similar Threads
Thread Thread Starter Forum Replies Last Post
Specified cast is not valid. ayem Visual Studio 2008 1 September 8th, 2008 09:15 PM
CAST function Adam H-W SQL Language 5 May 24th, 2007 04:27 AM
Specified cast is not valid. Jose P C# 5 May 11th, 2007 08:04 AM
"Specified cast is not valid" help BaBaBooey ASP.NET 1.0 and 1.1 Basics 2 November 23rd, 2004 12:12 PM
cast problem vickyj General .NET 6 September 8th, 2004 06:21 AM





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