處理C#vs 2008.我在SQL Server 2005中有一個存儲過程。使用Linq-to-SQL我執行存儲過程,但結果爲零。當我在Sql server中運行查詢時,它工作正常爲什麼存儲過程結果爲零?
exec spGetInvoiceByDate '03/01/2011 00:00:00 AM','03/31/2011 11:59:59 PM'
上面的語法工作正常。
,這裏是我的SQL Server 存儲過程
create procedure [spGetInvoiceByDate]
@Beginning_Date DateTime, @Ending_Date DateTime
as
begin
SELECT * INTO #temp1 FROM (
SELECT convert(varchar, ManifestPort.StartDate, 1)+'-'+CASE dbo.ManifestPort.EndDate WHEN '1800-01-01 00:00:00.000' THEN 'N/A' ELSE convert(varchar, ManifestPort.EndDate, 1) END AS [Date], Manifest.VesselName, Manifest.VoyageNo, DischargePort.PortName
, ManifestPort.Terminal, COUNT(Seal.ContainerNo) TotalContainers, 0 AS TotalHours, 0 AS TotalFee
FROM ManifestPort
INNER JOIN Manifest ON ManifestPort.ManifestNo = Manifest.ManifestNo
INNER JOIN DischargePort ON ManifestPort.PortCode = DischargePort.PortCode
INNER JOIN Seal ON ManifestPort.ManifestPortNo = Seal.ManifestPortNo
WHERE (StartDate BETWEEN @Beginning_Date AND @Ending_Date)
GROUP BY StartDate,EndDate, VesselName, VoyageNo, PortName, Terminal) AS a
SELECT * INTO #temp2 FROM (
SELECT convert(varchar, ManifestPort.StartDate, 1)+'-'+CASE dbo.ManifestPort.EndDate WHEN '1800-01-01 00:00:00.000' THEN 'N/A' ELSE convert(varchar, ManifestPort.EndDate, 1) END AS [Date], Manifest.VesselName, Manifest.VoyageNo, DischargePort.PortName,
ManifestPort.Terminal, COUNT(Seal.ContainerNo) STotalContainers, 0 AS STotalHours, 0 AS STotalFee
FROM ManifestPort
INNER JOIN Manifest ON ManifestPort.ManifestNo = Manifest.ManifestNo
INNER JOIN DischargePort ON ManifestPort.PortCode = DischargePort.PortCode
INNER JOIN Seal ON ManifestPort.ManifestPortNo = Seal.ManifestPortNo
WHERE (StartDate BETWEEN @Beginning_Date AND @Ending_Date) AND Line = 'CSAV'
GROUP BY StartDate,EndDate, VesselName, VoyageNo, PortName, Terminal ) AS b
SELECT #temp1.Date,
#temp1.VesselName ,
#temp1.VoyageNo ,
#temp1.PortName ,
#temp1.Terminal ,
#temp1.TotalContainers ,
#temp1.TotalHours ,
#temp1.TotalFee, #temp2.STotalContainers, #temp2.STotalHours, #temp2.STotalFee FROM #temp1 INNER JOIN #temp2
ON #temp1.Date = #temp2.Date AND #temp1.PortName = #temp2.PortName AND #temp1.Terminal = #temp2.Terminal AND #temp1.VesselName = #temp2.VesselName
AND #temp1.VoyageNo = #temp2.VoyageNo
Order BY #temp1.VesselName, #temp1.VoyageNo
DROP TABLE #temp1
DROP TABLE #temp2
end
我用這個C#的LINQ語法執行存儲過程:
DateTime firstDayOfMonth = Convert.ToDateTime("03/01/2011");
DateTime lastDayOfMonth = Convert.ToDateTime("03/31/2011");
var results = ProviderName.spGetInvoiceByDate(firstDayOfMonth,lastDayOfMonth);
爲什麼我總是得到的結果是零?
有人能告訴我如何減少這個問題嗎?
在此先感謝您,如果您有任何問題,請詢問。
你的意思是「結果爲零」是什麼意思?什麼是'spGetInvoiceByDate'方法的返回類型? – 2011-04-12 05:27:49
那麼,你需要逐步調試問題。給定那些輸入參數 - 存儲過程本身(在SQL Server Mgmt Studio中)是否返回?然後:嘗試逐個運行內部SELECT語句 - 它們實際上是否產生結果?如果不是:調查,爲什麼不。看起來像一個相當簡單和直接的調試會話 - 但沒有你的數據庫和你的表,試圖**猜**遠處發生了什麼是不可能的 – 2011-04-12 05:29:31
據我所知,proc是爲了返回一個結果集不是標量,也不是過程的返回值。所以,我懷疑任何人都不知道爲什麼你期望得到一些非零值的返回值。 – Thomas 2011-04-12 05:34:01