我试图将我的代码中的参数传递给我的水晶报告,但我一直收到错误
加载报告失败
我使用数据集将参数传递给crystal report。我的数据集有1列(Test1)
这是我在代码背后的代码
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
Dim path As String = Server.MapPath("~\Reports\CrystalReportTest.rpt")
Dim rptDoc As ReportDocument = New ReportDocument
rptDoc.SetDatabaseLogon("test", "test", "TestDB", "JulianPC", True)
Dim a As String = "10001"
Dim b As String = "10003"
rptDoc.Load(path)
rptDoc.FileName = "CrystalReportTest.rpt"
rptDoc.SetParameterValue("Test1", a)
CrystalReportViewer1.ReportSource = rptDoc
CrystalReportViewer1.Visible = True
Catch ex As Exception
End Try
End Sub
这是我的aspx代码
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="CrystalReportTest.rpt"></Report>
</CR:CrystalReportSource>
<table>
<tr>
<td>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" ReportSourceID="CrystalReportSource1" AutoDataBind="True" HasPrintButton="True" HasRefreshButton="True" ReuseParameterValuesOnRefresh="True" Height="50px" Width="350px"/>
</td>
</tr>
</table>
有谁能告诉我如何解决这个问题?
提前感谢您提供任何帮助
答案 0 :(得分:0)
您是否尝试传递此类参数
CrystalReportSource1.ReportDocument.SetParameterValue("parameter_name_as_String", "Value_as_String")
答案 1 :(得分:0)
尝试:
Imports CrystalDecisions
Imports CrystalDecisions.CrystalReports
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Dim RptDoc As New ReportDocument()
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
Dim crtableLogoninfo As New TableLogOnInfo
RptDoc.Load(Server.MapPath(Request.ApplicationPath + "/Reports/myReport.rpt"))
With crConnectionInfo
.ServerName = "myServer"
.DatabaseName = "myDatabase"
.UserID = "myUserID"
.Password = "myPassword"
End With
CrTables = RptDoc.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
RptDoc.SetDatabaseLogon(crConnectionInfo.UserID, crConnectionInfo.Password, crConnectionInfo.ServerName, crConnectionInfo.ServerName)
RptDoc.SetParameterValue("@myParameter", myValue)
Dim stream As New BinaryReader(RptDoc.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat))
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", Convert.ToString("attachment; filename=") & myDownloadAsFilename)
Response.AddHeader("content-length", stream.BaseStream.Length.ToString())
Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)))
Response.Flush()
Response.Close()