本文介绍了绑定变量作为Crystal Report的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我不知道主题是否对我的查询正确!! ...
我创建了21个水晶报表,分别将它们命名为GR01_rpt,GR02_rpt,GR03_rpt.... 21个报告中的每个报告都有其自己的格式.
为了减少冗长的编码,我创建了一个功能
Hello,
I don''t know if the Subject is correct my Query?!...
I have created 21 crystal reports naming them GR01_rpt, GR02_rpt, GR03_rpt.... GR021_rpt. Each of the 21 reports has its own format.
to lessen the long coding, i created a Function,
Public Function A01Control(ByVal txndate As String, ByVal curr_cd As String)
Dim rpt As New GR01_rpt < -- how can i make this variable string
'GR01_rpt is a Crystal Report
'GR01_ds is a DataSet for GR01_rpt
What I wanted to do is, <----------------------
Dim rpt As New xRpt
wherein xRpt can be either GR01_rpt, GR02_rpt GR03_rpt to GR21_rpt, Depending
on What Report the User Processes.
Also, How can i do it in the DataSet <------------------
Dim da As SqlDataAdapter = New SqlDataAdapter(comm)
Dim myDS As New GR01_ds()
da.Fill(myDS, myRPT)
rpt.SetDataSource(myDS)
ReportMain.CrystalReportViewer2.ReportSource = rpt
ReportMain.CrystalReportViewer2.Refresh()
End Function
Hope that my query is right??
推荐答案
dim rptFileName as string="GR01_rpt.rpt"
Dim rpt as new CrystalDecisions.CrystalReports.Engine.ReportDocument
rpt.Load(rptFileName)
希望对您有所帮助.
Hope it will help.
...
Dim da As SqlDataAdapter = New SqlDataAdapter(comm, sql(rptfileName))
Dim myDs as New DataSet()
da.Fill(myDS, myRPT)
rpt.SetDataSource(myDS)
ReportMain.CrystalReportViewer2.ReportSource = rpt
ReportMain.CrystalReportViewer2.Refresh()
...
Private Function sql(ByVal reportFile As String) As String
Select Case reportFile
Case "GR01_rpt.rpt"
Return "SELECT * FROM Table1"
Case "GR02_rpt.rpt"
Return "SELECT * FROM Table2"
End Select
End Function
Imports System.Reflection
...
dim ds as Dataset
ds=CreateDataset("GR01_ds")
...
Public Function CreateDataset(ByVal datasetName As String) As DataSet
Return DirectCast(CreateObjectInstance(datasetName), DataSet)
End Function
Public Function CreateObjectInstance(ByVal objectName As String) As Object
'' Creates and returns an instance of any object in the assembly by its type name.
Dim obj As Object
Try
If objectName.LastIndexOf(".") = -1 Then
''Appends the root namespace if not specified.
objectName = [Assembly].GetEntryAssembly.GetName.Name & "." & objectName
End If
obj = [Assembly].GetEntryAssembly.CreateInstance(objectName)
Catch ex As Exception
obj = Nothing
End Try
Return obj
End Function
这篇关于绑定变量作为Crystal Report的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!