2015-10-28 75 views
0

我有一個VB.Net應用程序,它使用來自各種數據源的數據集創建水晶報告,這些數據集進入單獨的子報表。該報告顯示正常,直到我嘗試使用存儲過程作爲子報表的數據源,在這種情況下,我收到錯誤「Invalid Report File Path」。無效的報告文件路徑錯誤 - 帶有存儲過程的Crystal Reports

此存儲過程需要將數字連接到列名以避免重複代碼。

我已經在數據集被填充的地方設置了斷點,檢查了數據集的內容,並發現所有需要的數據都在數據集中,但是當我逐步到達報告打開的位置時會出現錯誤。當我在SQL Server中執行存儲過程時,數據返回時沒有問題。如果我刪除使用存儲過程的子報表,報表將生成正常。想知道存儲過程是否需要以不同的方式編碼...?或者是其他東西?

下面是存儲過程

ALTER PROCEDURE [dbo].[T_STORED_PROC] 
(

@qmonth varchar(20), 
@qyear varchar (4), 
@qid varchar (10) 
) 
AS 


DECLARE @i varchar(10) 
DECLARE @sql varchar(1000) 

SET @i = 1 

WHILE (@i <=28) 
BEGIN 
SET @sql ='SELECT t1.ID, t2.CatId, t2.CatName, t1.M_'+ @i +'_DATE As Mid_Date 
FROM Table1 As t1, Table2 As t2 WHERE t2.CatId = RTRIM(LEFT(t1.M_'+ @i +', 2)) 
AND t1.ID = '''+ @qid +''' AND t1.Yr = '+ @qyear +' AND t1.M_Month = '''+ @qmonth +''' 
ORDER BY t1.ID' 

    EXEC (@sql) 

END 

和有關VB的代碼是在這裏

Dim dsQRpt = New Data.DataSet 
Dim dsMS = New Data.DataSet 
Dim QPrpt = New ReportDocument 

Dim cmd As OleDbCommand = New OleDbCommand() 
     cmd.Connection = MSCON 
     cmd.CommandType = CommandType.StoredProcedure 
     cmd.CommandText = "dbo.T_STORED_PROC" 
     cmd.Parameters.Add("@qmonth", OleDbType.VarChar, 20, ParameterDirection.Output).Value = cboMonth.SelectedValue 
     cmd.Parameters.Add("@qyear", OleDbType.VarChar, 4, ParameterDirection.Output).Value = cboYear.SelectedValue 
     cmd.Parameters.Add("@qid", OleDbType.VarChar, 10, ParameterDirection.Output).Value = txtPTSID.Text 

     Dim DAms As New OleDbDataAdapter(cmd.CommandText, MSCON) 

     DAms.SelectCommand = cmd 

     DAms.Fill(dsQRpt) 

     QPrpt.Load(Server.MapPath("crReport.rpt")) 
     QPrpt.SetDataSource(dsQRpt) 
     crQtrProgress.ReportSource = QPrpt 

感謝您的幫助

回答

0

我發現我的問題的解決方案。它看起來像Crystal Reports不識別存儲在SQL變量中的數據庫字段。我更改了存儲過程,以便查詢結果填充我創建的臨時表,然後從中獲取數據庫字段。這裏是工作存儲過程:

ALTER PROCEDURE [dbo].[T_STORED_PROC] 
(

@qmonth varchar(20), 
@qyear varchar (4), 
@qid varchar (10) 
) 
AS 

--Temp table 
DECLARE @tmp table 
(
ID nvarchar(10), 
CategoryId int, 
CategoryName nvarchar(50), 
CatDate datetime 
) 

DECLARE @i varchar(10) 
DECLARE @sql varchar(1000) 

SET @i = 1 

WHILE (@i <=28) 
BEGIN 
SET @sql ='SELECT t1.ID, t2.CatId, t2.CatName, t1.M_'+ @i +'_DATE As Mid_Date 
FROM Table1 As t1, Table2 As t2 WHERE t2.CatId = RTRIM(LEFT(t1.M_'+ @i +', 2)) 
AND t1.ID = '''+ @qid +''' AND t1.Yr = '+ @qyear +' AND t1.M_Month = '''+ @qmonth +''' 
ORDER BY t1.ID' 

--INSERT results into temp table 
INSERT INTO @tmp 

    EXEC (@sql) 

END 

--SELECT from temp table 
SELECT ID As ID, 
CategoryId AS CategoryId, 
CategoryName AS CategoryName, 
CatDate As CatDate 
FROM @tmp 
相關問題