|
-
Jul 2nd, 2008, 10:16 PM
#1
Thread Starter
Junior Member
sub report unable to logon
Hi guys,
i am a newbie in crystal report. I having some trouble using subreport. I use the push method to populate the data sourece. The code is as below.
If Session("username") = "" Then
Response.Redirect("~/NoAccess.htm")
Return
End If
cnn.openSql()
If IsPostBack = False Then
Dim dt As DataTable
Dim subdt As DataTable
Dim con As CrystalDecisions.Shared.ConnectionInfo
Dim str As String
Dim i As Integer
i = 0
Dim MainReport As Engine.ReportDocument
Dim Subreport As Engine.ReportDocument
Subreport = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
MainReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
MainReport.Load("C:\Project1\Report\MainPart.rpt")
CrystalReportViewer1.ReportSource = MainReport
sql = "SELECT xxx from yyy where xxx=something"
dt = cnn.query(sql)
MainReport.SetDataSource(dt)
sql = "SELECT yyy from xxx where yyy=somethingelse"
subdt = cnn.query(sql)
Subreport.Load("C:\Project1\Report\SubPart.rpt")
MainReport.OpenSubreport("SubPart.rpt")
If subdt.Rows.Count < 0 Then
Else
Subreport.SetDataSource(subdt)
End If
CrystalReportViewer1.DataBind()
CrystalReportViewer1.DisplayToolbar = False
End If
What is wrong? Please advice
-
Jul 3rd, 2008, 11:55 AM
#2
Re: sub report unable to logon
You are opening and setting the datasource of the SubPart.rpt file directly, ie as if it were a main report. Don't create a new instance of the ReportDocument object for the SubReport variable, use the instance returned by calling the MainReport.OpenSubReport method.
Dim MainReport As Engine.ReportDocument
Dim Subreport As Engine.ReportDocument
MainReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
MainReport.Load("C:\Project1\Report\MainPart.rpt")
SubReport = MainReport.OpenSubreport("SubPart.rpt")
sql = "SELECT xxx from yyy where xxx=something"
dt = cnn.query(sql)
MainReport.SetDataSource(dt)
sql = "SELECT yyy from xxx where yyy=somethingelse"
subdt = cnn.query(sql)
Subreport.SetDataSource(subdt)
CrystalReportViewer1.ReportSource = MainReport
CrystalReportViewer1.DataBind()
CrystalReportViewer1.DisplayToolbar = False
-
Jul 3rd, 2008, 07:41 PM
#3
Thread Starter
Junior Member
Re: sub report unable to logon
Thanks brucevde,
I do some research and solved the unable to logon but now it seem another error occured, for the second sub report. the error is "The table could not be found" Below is the code
Dim ds As DataSet
ds = New DataSet
Dim ds2 As DataSet
ds2 = New DataSet
Dim str As String
Dim i As Integer
i = 0
Dim mainr As Engine.ReportDocument
Dim MainReport As Engine.ReportDocument
Dim Subreport As Engine.ReportDocument
mainr = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
MainReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
Subreport = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
mainr.Load("C:\Project1\Report\Main.rpt")
Dim sbb As SubreportObject = TryCast(mainr.ReportDefinition.ReportObjects("Subreport1"), SubreportObject)
Dim sbb2 As SubreportObject = TryCast(mainr.ReportDefinition.ReportObjects("Subreport2"), SubreportObject)
If sbb IsNot Nothing Then
' Get the subreport name.
str = sbb.SubreportName
' Open the subreport as a ReportDocument.
MainReport = sbb.OpenSubreport(str)
End If
If sbb2 IsNot Nothing Then
' Get the subreport name.
str = sbb2.SubreportName
' Open the subreport as a ReportDocument.
Subreport = sbb2.OpenSubreport(str)
End If
sql = "SELECT xxx from yyy where xxx=something"
ds.Tables.Add(cnn.query(sql))
MainReport.SetDataSource(ds.Tables(0))
sql = "SELECT yyy from xxx where yyy=somethingelse"
ds2.Tables.Add(cnn.query(sql))
Subreport.SetDataSource(ds2.Tables(0))
Dim _applyLogin As New ReportLogon
' use ApplyLogin object to apply login info to all tables in CR object
_applyLogin._dbName = "tracking"
_applyLogin._passWord = "admin1"
_applyLogin._serverName = "localhost"
_applyLogin._userID = "root"
_applyLogin.ApplyInfo(mainr)
_applyLogin.ApplyInfo(MainReport)
_applyLogin.ApplyInfo(SubReport)
CrystalReportViewer1.ReportSource = mainr
CrystalReportViewer1.DataBind()
CrystalReportViewer1.DisplayToolbar = False
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|