任何人都知道为什么以下内容不起作用:
[WebMethod()]
public double GetDayCount(string strMeetingDate, string strMeetingTime)
{
string[] strStartDateParts = strMeetingDate.Split('-');
// change DMY to YMD
strMeetingDate = strStartDateParts[2] + '-' + strStartDateParts[1] + '-' + strStartDateParts[0];
using (connection = new SqlConnection(ConfigurationManager.AppSettings["connString"]))
{
using (command = new SqlCommand("BusinessHours", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@meeting_day", SqlDbType.DateTime).Value = strMeetingDate;
command.Parameters.Add("@meeting_time", SqlDbType.DateTime).Value = strMeetingTime;
connection.Open();
using (reader = command.ExecuteReader())
{
reader.Read();
return (double)reader["hours"];
}
}
}
}
没有返回错误消息,而是返回的值不正确。
这是一个完整的存储过程。
USE [INTRANET]
GO
/****** Object: StoredProcedure [dbo].[BusinessHours] Script Date: 06/24/2013 11:38:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[BusinessHours]
@meeting_day DATETIME,
@meeting_time DATETIME
AS
DECLARE @submit_day DATETIME;
DECLARE @submit_time DATETIME;
DECLARE @start_time_of_business_day DATETIME;
DECLARE @business_day_hours FLOAT;
DECLARE @num1 FLOAT
DECLARE @num2 FLOAT
DECLARE @num3 FLOAT
SET @submit_day = CONVERT(VARCHAR(10),GETDATE(),101);
SET @submit_time = CONVERT(VARCHAR(8),GETDATE(),108);
SET @start_time_of_business_day = '09:00';
SET @business_day_hours = 8.5;
SET @num1 = ((DATEDIFF(dd, @submit_day, @meeting_day))
-(DATEDIFF(wk, @submit_day, @meeting_day) * 2)
-(CASE WHEN DATEPART(dw, @submit_day) = 1 THEN 1 ELSE 0 END)
-(CASE WHEN DATEPART(dw, @meeting_day) = 7 THEN 1 ELSE 0 END)
-(SELECT COUNT(*) FROM bank_holiday WHERE the_date BETWEEN @submit_day AND @meeting_day)) * @business_day_hours
SET @num2 = (select datediff(minute, @start_time_of_business_day, @submit_time)) / 60.0
SET @num3 = (select datediff(minute, @start_time_of_business_day, @meeting_time)) / 60.0
select @num1 - @num2 + @num3 as [hours]
如果我手动运行存储过程(如通过单击存储过程名称并选择执行从 sql server management studio 中执行它),我得到 0.666667(值将根据当前日期/时间和输入的日期/时间而有所不同进入存储过程)。但是当我运行 .asmx 文件时,我得到 994728.666667。
有谁知道为什么会这样?基本上,两个示例中的 .666667 部分都是正确的,但由于某种原因,.asmx 文件似乎将 994728 添加到正确的值。