on 09-01-2008 12:40 PM
Hi,
How to load the report in VB.Net.This is my Code:
Public Class ReportFunctions
Enum ParamType As Integer
Int
Text
End Enum
Public Shared Sub SetCrystalLogin(ByVal sUser As String, ByVal sPassWord As String, ByVal sServer As String, ByVal sCompanyDB As String, ByRef oRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument)
Dim oDB As CrystalDecisions.CrystalReports.Engine.Database = oRpt.Database
Dim oTables As CrystalDecisions.CrystalReports.Engine.Tables = oDB.Tables
Dim oLogOnInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim oConnectInfo As CrystalDecisions.Shared.ConnectionInfo = New CrystalDecisions.Shared.ConnectionInfo()
Try
oConnectInfo.DatabaseName = sCompanyDB
oConnectInfo.ServerName = sServer
oConnectInfo.UserID = sUser
oConnectInfo.Password = sPassWord
For Each oTable As CrystalDecisions.CrystalReports.Engine.Table In oTables
oLogOnInfo = oTable.LogOnInfo
oLogOnInfo.ConnectionInfo = oConnectInfo
oTable.ApplyLogOnInfo(oLogOnInfo)
Next
Dim oSections As CrystalDecisions.CrystalReports.Engine.Sections
Dim oSection As CrystalDecisions.CrystalReports.Engine.Section
Dim oRptObjs As CrystalDecisions.CrystalReports.Engine.ReportObjects
Dim oRptObj As CrystalDecisions.CrystalReports.Engine.ReportObject
Dim oSubRptObj As CrystalDecisions.CrystalReports.Engine.SubreportObject
Dim oSubRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument
oSections = oRpt.ReportDefinition.Sections
For Each oSection In oSections
oRptObjs = oSection.ReportObjects
For Each oRptObj In oRptObjs
If oRptObj.Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
oSubRptObj = CType(oRptObj, CrystalDecisions.CrystalReports.Engine.SubreportObject)
oSubRpt = oSubRptObj.OpenSubreport(oSubRptObj.SubreportName)
oDB = oSubRpt.Database
oTables = oDB.Tables
For Each oTable As CrystalDecisions.CrystalReports.Engine.Table In oTables
oLogOnInfo = oTable.LogOnInfo
oLogOnInfo.ConnectionInfo = oConnectInfo
oTable.ApplyLogOnInfo(oLogOnInfo)
Next
End If
Next
Next
Catch Ex As Exception
Throw Ex
End Try
End Sub
Public Shared Sub SetCrystalParams(ByVal sFieldName As String, ByVal iDataType As ParamType, ByVal sVal As String, ByVal oRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument)
Dim oFieldDefs As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions
Dim oFieldDef As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
Dim oParamVals As CrystalDecisions.Shared.ParameterValues
Dim oDiscreteVal As CrystalDecisions.Shared.ParameterDiscreteValue
Try
oFieldDefs = oRpt.DataDefinition.ParameterFields
oFieldDef = oFieldDefs(sFieldName)
oParamVals = oFieldDef.CurrentValues
oParamVals.Clear()
oDiscreteVal = New CrystalDecisions.Shared.ParameterDiscreteValue()
Select Case iDataType
Case ParamType.Int
oDiscreteVal.Value = System.Convert.ToInt32(sVal)
Case ParamType.Text
oDiscreteVal.Value = sVal
End Select
oParamVals.Add(oDiscreteVal)
oFieldDef.ApplyCurrentValues(oParamVals)
Catch ex As Exception
Throw ex
End Try
End Sub
End Class
In my addon print button click ia have called this function:
Private Sub LoadReport(ByVal ReportName As String)
Dim RptCrystal As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim sPath As String
Try
sPath = System.IO.Directory.GetParent(Application.StartupPath).ToString()
RptCrystal.Load(sPath & "\Forms\" & ReportName)
ReportFunctions.SetCrystalLogin("sa", "sapb1@sql", Company.Server, Company.CompanyDB, RptCrystal)
Catch Ex As Exception
Throw Ex
End Try
End Sub
Ther is no error in my code.But the report is not loading.How to solve this problem.
Thanx in advance
Mohana
HI Mohana,
You are using a long method of coding, what I mean to say is as we are not getting any specific error (Or is there any any?) lets make it simpler by just loading the report to viewer and view it.
For this you can use the following code:
// namespaces
imports CrystalDecisions.CrystalReports.Engine
imports CrystalDecisions.Shared
Imports CrystalDecisions.Web
Dim Rdoc as new ReportDocument()
Rdoc.Load("C:\Windows\Temp\Report.rpt")
CrystalViewer1.ReportSource=Rdoc
The report will prompt for parameters and database logon and should display the report in form.
If it does not then check if the report is working fine from designer or not. Schema should not be changed and
let us know the VS and CR product and its version you are using along with the patch level applied.
You can try these [samples|https://boc.sdn.sap.com/samples/1173/84/1201].
Hope that helps!
Regards,
AG.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mohana,
Let's try these:
1) Do not declare any objects for Crystal Report Viewer Control. Use the name of the Viewer.
2) Does the report displays properly from the designer?
3) Take a sample report available in your system under Business objects Folder in Program Files and try with the application.(Just to make sure if this is related to this report or all the reports.) In case you are using the Cr that comes with VS then you will find sample reports under Microsoft Net folder.
4) Give us the product details of VS and CR with editions so that we can try this at our end also.
Let us know if this helps!
Regards,
AG.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.