我试图将参数传递给crystal report viewer。但它显示参数不正确。
Dim rpt As New ReportDocument
rpt.FileName = My.Application.Info.DirectoryPath & "\MAuditList.rpt"
Dim paramDV As New ParameterDiscreteValue()
paramDV.Value = frmMachine.machine
rpt.ParameterFields("@mchno").CurrentValues.Clear()
rpt.ParameterFields("@mchno").DefaultValues.Clear()
rpt.ParameterFields("@mchno").CurrentValues.Add(paramDV)
paramDV.Value = frmMachine.batch - 1
rpt.ParameterFields("@batch").CurrentValues.Clear()
rpt.ParameterFields("@batch").DefaultValues.Clear()
rpt.ParameterFields("@batch").CurrentValues.Add(paramDV)
paramDV.Value = InpStdPt
rpt.ParameterFields("@Points").CurrentValues.Clear()
rpt.ParameterFields("@Points").DefaultValues.Clear()
rpt.ParameterFields("@Points").CurrentValues.Add(paramDV)
paramDV.Value = OvrPoints
rpt.ParameterFields("@ovrpt").CurrentValues.Clear()
rpt.ParameterFields("@ovrpt").DefaultValues.Clear()
rpt.ParameterFields("@ovrpt").CurrentValues.Add(paramDV)
Form1.CrystalReportViewer1.ReportSource = rpt
Form1.Show()</code>
这些代码中的任何错误??
答案 0 :(得分:0)
您应该将参数分配给Report对象,然后将报表对象分配给CrystalReportViewer。
尝试这样的事情:
'Create report object and load the report
Dim rpt As New ReportDocument()
rpt.FileName = My.Application.Info.DirectoryPath & "\MAuditList.rpt"
'Set the Parameters
Dim paramDV As New ParameterDiscreteValue()
paramDV.Value = "Parameter Value"
rpt.ParameterFields("@ParameterName").CurrentValues.Clear()
rpt.ParameterFields("@ParameterName").DefaultValues.Clear()
rpt.ParameterFields("@ParameterName").CurrentValues.Add(paramDV)
'Assign the report object to the Viewer Report Source
Form1.CrystalReportViewer1.ReportSource = rpt
Form1.Show()