绑定变量作为Crystal Report [英] Binding variable as Crystal Report
本文介绍了绑定变量作为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??
推荐答案
您可以存储Crystal报告文件( * .rpt)在程序目录中.在解决方案资源管理器中的文件(rpt)属性上,设置构建操作"-无",复制到输出目录"-如果更新则复制".
加载报告的代码为:
You can store crystal report files (*.rpt ) in program directory . On file (rpt) properties in solution explorer, set "Build action" - ''None'', "Copy to Output Directory" - ''Copy if newer''.
The code to load report is:
dim rptFileName as string="GR01_rpt.rpt"
Dim rpt as new CrystalDecisions.CrystalReports.Engine.ReportDocument
rpt.Load(rptFileName)
希望对您有所帮助.
Hope it will help.
艾伦,
您可以为每个报表的数据适配器使用不同的SQL,而不是使用不同的数据集名称,例如:
Hi Alan,
you can use different sqls for each report''s dataadapter instead of using different dataset name, for example:
...
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
Alan,我发现需要我以前通过其名称加载表单的代码.希望对您有帮助
Alan, I found required code I used to load form by it''s name . Hope it will help
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文