我想从asp.net项目中的sql server只获取来自存储过程的变量值 [英] i want to get only count variable value from store procedure from sql server in asp.net project
本文介绍了我想从asp.net项目中的sql server只获取来自存储过程的变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的商店程序是
my store procedure is
ALTER PROCEDURE [dbo].[AttendenceMonthly]
@EmployeeId int
AS
declare @i int
declare @nowdate datetime,@redusedatetime datetime,@redusedate datetime,@newdate datetime,@count int,@affectedrow int
Declare @p AS NVarchar(4000)
set @nowdate =GETDATE()
set @redusedatetime=DATEADD(DD,-21,@nowdate)
set @redusedate =CONVERT(varchar(10),@redusedatetime,23)
set @p=0
BEGIN
set @i=1
set @count=0
while(@i <= (select datediff(day, GETDATE(), dateadd(month, 1, GETDATE()))))
begin
select * from TblAttendence where convert(varchar(10),LoginTime,23) = @redusedate and EmployeeId =@EmployeeId
if @@ROWCOUNT = 1
begin
set @count =@count +1
end
set @redusedate=DATEADD(DD,+1,@redusedate)
set @redusedate=CONVERT(varchar(10),@redusedate,23)
set @i=@i+1
end
select @count
END
i只想在我的项目中计算值
i want only count value in my project
推荐答案
public static int AttendenceMonthly(int employeeId)
{
int AttendenceMonthly = -1;
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [myconnectionstring]。ConnectionString);
SqlCommand cmd = new SqlCommand(AttendenceMonthly,conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(@ EmployeeId,employeeId);
试试
{
conn.Open();
order_id = Int32.Parse(cmd.ExecuteScalar()。ToString());
返回order_id;
}
catch(SqlException se)
{
System.Console.WriteLine(se.Message);
}
conn.Close();
返回AttendenceMonthly;
}
public static int AttendenceMonthly(int employeeId)
{
int AttendenceMonthly = -1;
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString);
SqlCommand cmd = new SqlCommand("AttendenceMonthly", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@EmployeeId", employeeId);
try
{
conn.Open();
order_id = Int32.Parse(cmd.ExecuteScalar().ToString());
return order_id;
}
catch (SqlException se)
{
System.Console.WriteLine(se.Message);
}
conn.Close();
return AttendenceMonthly;
}
这篇关于我想从asp.net项目中的sql server只获取来自存储过程的变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文