Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > Visual Studio 2008
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 3rd, 2009, 12:05 AM
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Linq: 'Specified cast is not valid' error exception.

Hi All,
I’m in a big problem.
I'm using WCF service and LINQ for our Silverlight 2 application.
In my application I'm fetching records from the SQL database using the stored procedure. Below is the interface of my procedure
List<Usp_GetReportDataResult> GetReportData(int JobId, DateTime StartDate, DateTime EndDate)
For some JobId I’m able to get the data successfully, but for most of the JobIds I’m getting 'Specified cast is not valid' error exception. JobId is a unique key field of title table.
Below is the Web Method to get the result using LINQ statement:
publicList<Usp_GetReportDataResult> GetReportData(int JobId, DateTime StartDate, DateTime EndDate)
{
// Call to get record from the Database
WMDBDataContext db = newWMDBDataContext();
var matchingRecords = from Report in db.Usp_GetReportData(JobId, StartDate, EndDate)
select Report;
return matchingRecords.ToList(); //Error is coming in this line.
}
Below are the fields and datatypes generated by the LINQ Designer class for Usp_GetReportData.
privatestring _Status;
privatestring _Protocol;
privatestring _Country;
privatestring _CountryID;
privatestring _LanguageName;
privatestring _Subtitles;
private System.Nullable<short> _VideoID;
private System.Nullable<System.DateTime> _LastSeenDateET;
private System.Nullable<int> _DownloadCounts;
privatechar _AdjustedInd;
private System.Nullable<long> _FileSize;
private System.Nullable<byte> _HourNumber;
privatestring _IPAddress;
==========================================
Thanks,
Mahesh
Reply With Quote
  #2 (permalink)  
Old February 4th, 2009, 06:28 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Mahesh,

Try doing this:
csharp Code:
return (from Report in db.Usp_GetReportData(JobId, StartDate, EndDate) select Report).ToList();
__________________
-Peter
compiledthoughts.com
twitter/peterlanoie
Reply With Quote
  #3 (permalink)  
Old February 4th, 2009, 11:06 PM
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for you help.

But it did not work.

My DBA guy has fixed the problem. It was due to tinyInt datatype of hourly field. In case of default value we have taken 0, it act 0 as int that was the real cause of problem. Now he has taken default value 0 as tinyint and it works.

Thanks
Mahesh
Reply With Quote
Reply


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
Specified cast is not valid heba ASP.NET 2.0 Professional 1 May 27th, 2007 08:51 PM
Specified cast is not valid surajb Crystal Reports 0 January 12th, 2007 02:03 PM
Error: "Specified cast not valid" on ItemDataBoun snejsnej ASP.NET 1.0 and 1.1 Professional 0 May 24th, 2006 05:36 PM
"Specified cast is not valid" help BaBaBooey ASP.NET 1.0 and 1.1 Basics 2 November 23rd, 2004 12:12 PM



All times are GMT -4. The time now is 08:18 PM.


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