Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > Visual Studio 2008
|
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 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 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
 
Old February 4th, 2009, 06:28 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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
 
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





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





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