处理“指定的演员表无效";使用linq到sql时出错 [英] handling "specified cast is not valid" error while using linq to sql

查看:85
本文介绍了处理“指定的演员表无效";使用linq到sql时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LINQ to SQL从SQL Server调用存储的proc,该proc返回具有特定字段的记录.
这是我的proc

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



并在后面的代码中,我想在某些文本框中显示proc返回的值.为此,我尝试了以下方法



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?

推荐答案

事实证明LINQ to SQL有一个错误! 每当存储过程返回没有"COLUMN NAME"的结果时,都会遇到此错误.
在我的情况下,SUM(atten.dailyhours)列没有名称,这是导致错误的原因!
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!


这篇关于处理“指定的演员表无效";使用linq到sql时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆