Click here to Skip to main content
13,458,920 members
Rate this:
Please Sign up or sign in to vote.
I am using LINQ to SQL to call a stored proc from SQL server which returns a record with certain feilds.
here is my proc
ALTER PROCEDURE [dbo].calculatePaylroll
	-- Add the parameters for the stored procedure here
	@empId varchar(50),
	@month int
declare @employee uniqueidentifier


select  @employee=CONVERT(uniqueidentifier,@empId);

select emp.User_Id,count (atten.time_in)
 as 'days' ,SUM(atten.dailyhours),emp.basic_salary
 from tbl_employees emp
 join tbl_Emp_Atten atten
 on emp.User_Id=atten.Emp_ID 
 where MONTH(date)=@month
 and emp.User_Id=@employee
 group by emp.User_Id,emp.basic_salary      

and in code behind i want to show the values returned by the proc in certain textboxes. For which i have tried following method
 public float calculateSalary( string empId,int month)
               EasyCutDataDataContext dbc = new EasyCutDataDataContext();
               //List<calculatePaylrollResult> res= dbc.calculatePaylroll(empId, month).ToList();
//METHOD 2  
             var result = dbc.calculatePaylroll(empId, month);
               string sal = "";
               foreach (getdetailsforedtingcustomersResult res in resut)
                   txtmonsalary.Text = res.Address .ToString();
                   //txtdays.Text = res.days.ToString();
                   //txthours.Text = res.Column1.ToString();

but I get this error : "Specified cast is not valid"
Can anyone please help me with this?
Posted 18-Jun-12 23:55pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

turns out that LINQ to SQL has a bug!
this error is encountered whenever a stored procedure returns the result without COLUMN NAME.
In my case the column SUM(atten.dailyhours) had no name that was the reason for the error!
Member 11001414 8-Aug-14 18:43pm
I had the same exact problem. I searched for " linq stored procedure specified cast not valid" and found this page. I had a count(*) in my stored procedure. I gave it an alias and now it works! Thanks sainju.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04-2016 | 2.8.180323.1 | Last Updated 19 Jun 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100