Calling Crystal report viewer in dot net

October 23, 2007 at 12:57 pm | In Dot Net | Leave a Comment

Using Crystal report in dot net

Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

Dim intCounter As Integer
Dim intCounter1 As Integer

‘Crystal Report’s report document object
Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument

‘object of table Log on info of Crystal report
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo

‘Sub report object of crystal report.
Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject

‘Sub report document of crystal report.
Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument

Dim index As Integer

‘Load the report
objReport.Load()

‘Set the connection information
ConInfo.ConnectionInfo.UserID =
ConInfo.ConnectionInfo.Password =
ConInfo.ConnectionInfo.ServerName =
ConInfo.ConnectionInfo.DatabaseName =

For intCounter = 0 To objReport.Database.Tables.Count – 1
objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
Next

‘ Loop through each section on the report then look
‘ through each object in the section
‘ if the object is a subreport, then apply logon info
‘ on each table of that sub report

For index = 0 to objReport.ReportDefinition.Sections.Count – 1
For intCounter = 0 To _
objReport.ReportDefinition.Sections(index).ReportObjects.Count – 1
With objReport.ReportDefinition.Sections(index)
If .ReportObjects(intCounter).Kind = _
CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
mySubReportObject = CType(.ReportObjects(intCounter), _
CrystalDecisions.CrystalReports.Engine.SubreportObject)
mySubRepDoc = _
mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count – 1
mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo( _
ConInfo)
mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo( _
ConInfo)
Next
End If
End With
Next
Next

‘If there is a selection formula
If sSelectionFormula.Length > 0 Then
objReport.RecordSelectionFormula = sSelectionFormula
End If

‘Formula fields in string with key-value pair.
‘Key-value separated by comma and forumlas are seperated by |
If sFormulas.Trim() “” Then
Dim sFormulaWithValues() As String = Split(sFormulas, “|”)
Dim i As Integer
For i = 0 To UBound(sFormulaWithValues)
Dim sFormulaValue() As String = Split(sFormulaWithValues(i), “,”)
objReport.DataDefinition.FormulaFields(sFormulaValue(0)).Text = sFormulaValue(1)
Next i
End If

‘Report file name
sFileName = AppDomain.CurrentDomain.BaseDirectory & “reports\” & sFileName

CrystalReportViewer1.ReportSource = objReport
CrystalReportViewer1.RefreshReport()
CrystalReportViewer1.DataBind()
‘Toolbar
CrystalReportViewer1.DisplayToolbar = True
‘Group tree
CrystalReportViewer1.DisplayGroupTree = False

Split() function

October 23, 2007 at 7:31 am | In Crystal Report | 2 Comments

Using split() function with array in crystal report

// 1) To return single element value in string
local stringVar array ;
local stringVar returnValue;

:=Split({},’;'); // Split(,delimeter);

returnValue:=[0];

// 2) To return all elements in string
local numbervar asize := ubound();
local numbervar x;
local stringvar returnValue:=”";

for x := 1 to asize do
(
returnValue := returnValue & [x] & ” “;
);

returnValue;

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.