connecting to Crystal subreports using vb.net

C

Craig G

we have a vb.net app that displays a series of reports

this is all working fine when it is just one report, but if we have a report which contains a subreport then it fails, i assume you need to logon to the subreports also but im not sure how to.

the subreports also require 4 parameter values to be passed to it

any help would be greatly appreciated

Cheers,
Craig



here is the code we use for calling a single report
************************************************************

Private Function fun_ShowReport() As Boolean

Dim obj_Report As New CrystalDecisions.CrystalReports.Engine.ReportDocument

Dim frm_Viewer As New frmViewReport

Dim crTableLogonInfo As TableLogOnInfo

Dim crConnectionInfo As ConnectionInfo

Dim crTable As CrystalDecisions.CrystalReports.Engine.Table

Try

crTableLogonInfo = New TableLogOnInfo

crConnectionInfo = New ConnectionInfo

crConnectionInfo.DatabaseName = g_str_Database

crConnectionInfo.ServerName = g_str_Server

crConnectionInfo.UserID = g_str_Username

crConnectionInfo.Password = g_str_Password

crTableLogonInfo.ConnectionInfo = crConnectionInfo

With obj_Report

..Load(m_str_ReportFilename)

For Each crTable In .Database.Tables

crTable.ApplyLogOnInfo(crTableLogonInfo)

Next

..SetParameterValue("@FromDate", txt_StartDate.SetDBValue)

..SetParameterValue("@ToDate", txt_EndDate.SetDBValue)

If m_int_ReportName <> ReportName.Report_UserFeedback Then

..SetParameterValue("@HospitalID", fun_SetNull(clsPharmacyClass.ReportHospital))

..SetParameterValue("@WardID", fun_SetNull(clsPharmacyClass.ReportWard))

End If

Select Case m_int_ReportName

Case ReportName.Report_Intervention

..SetParameterValue("@PatientID", 0)

..SetParameterValue("@PharmacistID", fun_SetNull(clsPharmacyClass.ReportPharmacist))

Dim int_InterventionComplete As Object

Dim sys_NullValue As System.DBNull

Select Case cbo_Filter.SelectedIndex

Case 0

int_InterventionComplete = sys_NullValue

Case 1

int_InterventionComplete = 0

Case 2

int_InterventionComplete = 1

End Select

..SetParameterValue("@InterventionComplete", int_InterventionComplete)

..SetParameterValue("@int_Mode", 1)

Case ReportName.Report_MonthlyActivity

..SetParameterValue("@PharmacistID", fun_SetNull(clsPharmacyClass.ReportPharmacist))

End Select

..SetDatabaseLogon(g_str_Username, g_str_Password, g_str_Server, g_str_Database)

End With

If ysd_Destination.StringValue = "Screen" Then

frm_SuccessMessage.fun_OpenForm _

("Printing to screen - Please wait....")

frm_Viewer.crv_ReportViewer.ReportSource = obj_Report

frm_Viewer.ShowDialog()

Else

frm_SuccessMessage.fun_OpenForm _

("Printing - Please wait....")

obj_Report.PrintToPrinter(1, True, 0, 0)

End If

Return True

Catch ex As Exception

ErrorMessage("Unable to show report " & _

ControlChars.CrLf & "Error Message: " & ex.Message.ToString)

Return False

Finally

obj_Report = Nothing

frm_Viewer = Nothing

End Try

End Function
 
G

Greg Young

this is C# and its setting the datasource for the subreports but the logic
is almost identical

private void SetReportDataSource(ReportDocument _Report, DataSet _ds) {
_Report.SetDataSource(_ds) ;

for (int i = 0; i < _Report.ReportDefinition.ReportObjects.Count; i++) {
ReportObject CurrentObject = _Report.ReportDefinition.ReportObjects;

if(CurrentObject.Kind ==
CrystalDecisions.Shared.ReportObjectKind.SubreportObject) {
ReportDocument SubReport =
_Report.OpenSubreport(((SubreportObject)CurrentObject).SubreportName);
SetReportDataSource(SubReport, _ds) ;
}
}
}

so in vb.net the basic logic is ...
private sub SetReportLogon(ByVal Report as ReportDocument)
int i

'set logon info

for i = 0 to Report.ReportDefinition.ReportObjects.Count - 1
dim CurrentObject as ReportObject=
Report.ReportDefinition.ReportObjects

if CurrentObject.Kind =
CrystalDecisions.Shared.ReportObjectKind.SubreportObject
dim SubReport as ReportDocument =
_Report.OpenSubreport(directcast(CurrentObject,subreportobject).SubreportNam
e)
SetReportDataSource(SubReport)
end if
next
end sub

Cheers,

Greg
 
G

Greg Young

glad I could help.
CJ Taylor said:
Thanks greg, I know this wasn't for me. But greatly helped!

-CJ

Greg Young said:
this is C# and its setting the datasource for the subreports but the logic
is almost identical

private void SetReportDataSource(ReportDocument _Report, DataSet _ds) {
_Report.SetDataSource(_ds) ;

for (int i = 0; i < _Report.ReportDefinition.ReportObjects.Count;
i++)
{
ReportObject CurrentObject = _Report.ReportDefinition.ReportObjects;

if(CurrentObject.Kind ==
CrystalDecisions.Shared.ReportObjectKind.SubreportObject) {
ReportDocument SubReport =
_Report.OpenSubreport(((SubreportObject)CurrentObject).SubreportName);
SetReportDataSource(SubReport, _ds) ;
}
}
}

so in vb.net the basic logic is ...
private sub SetReportLogon(ByVal Report as ReportDocument)
int i

'set logon info

for i = 0 to Report.ReportDefinition.ReportObjects.Count - 1
dim CurrentObject as ReportObject=
Report.ReportDefinition.ReportObjects

if CurrentObject.Kind =
CrystalDecisions.Shared.ReportObjectKind.SubreportObject
dim SubReport as ReportDocument =

_Report.OpenSubreport(directcast(CurrentObject,subreportobject).SubreportNam
e)
SetReportDataSource(SubReport)
end if
next
end sub

Cheers,

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top