1
Reply

LINQ: Specified cast is not valid error.

Mahesh Singh

Mahesh Singh

Feb 2 2009 1:46 AM
15k

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.

Below is the Web Method to get the result using LINQ statement:

public List<Usp_GetReportDataResult> GetReportData(int JobId, DateTime StartDate, DateTime EndDate)

{

// Call to get record from the Database

WMDBDataContext db = new WMDBDataContext();

var matchingRecords = from Report in db.Usp_GetReportData(JobId, StartDate, EndDate)

select Report;

return matchingRecords.ToList();

}

Below are the fields and datatypes generated by the LINQ Designer class for Usp_GetReportData.

private string _Status;

private string _Protocol;

private string _Country;

private string _CountryID;

private string _LanguageName;

private string _Subtitles;

private System.Nullable<short> _VideoID;

private System.Nullable<System.DateTime> _LastSeenDateET;

private System.Nullable<int> _DownloadCounts;

private char _AdjustedInd;

private System.Nullable<long> _FileSize;

private System.Nullable<byte> _HourNumber;

private string _IPAddress;

==========================================

Thanks,

Mahesh


Answers (1)