Click here to Skip to main content
11,415,973 members (83,084 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL LINQ Server
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
AS
declare @employee uniqueidentifier
 
BEGIN
 
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      
END

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();
//METHOD 1
               //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 19-Jun-12 0:55am

1 solution

Rate this: bad
good
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!
  Permalink  
Comments
Member 11001414 at 8-Aug-14 18:43pm
   
I had the same exact problem. I searched for "vb.net 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
0 Sergey Alexandrovich Kryukov 9,270
1 OriginalGriff 7,512
2 Maciej Los 3,710
3 Abhinav S 3,325
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web02 | 2.8.150427.4 | Last Updated 19 Jun 2012
Copyright © CodeProject, 1999-2015
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