无效的报告文件路径错误 - Crystal Reports w /存储过程

时间:2015-10-28 13:34:21

标签: sql-server vb.net stored-procedures crystal-reports

我有一个VB.Net应用程序,它使用来自各个数据源的数据集创建一个水晶报告,这些数据集分为不同的子报告。报告显示正常,直到我尝试将存储过程用作子报表的数据源,在这种情况下,我收到错误"无效的报告文件路径"。

此存储过程需要将数字连接到列名,以避免重复代码。

我已经在填充数据集的位置设置了断点,检查了数据集内容,发现所有需要的数据都在数据集中,但是当我逐步到达这一点时,我会得到错误报告打开。当我在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

感谢您的帮助

1 个答案:

答案 0 :(得分: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