bigfoot (Programmer) |
30 Nov 07 9:07 |
If you don't mind the code in VB.NET, then I can help. It's not so bad, but there are a few things you have to watch out for. Throw a CR Viewer on a page. CODE <CR:CrystalReportViewer ID="CReportViewer" runat="server" AutoDataBind="true" Style="z-index: 18; position: absolute; left: 0px; top: 0px" DisplayGroupTree="False" /> This class behind takes care of logging in, setting the params and displaying the report. CODEPartial Class ViewReport Inherits System.Web.UI.Page
'Crystal report configuration code needs to be called earlier, during the Page.Init event. Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init ConfigureCrystalReports() End Sub
'The ConfigureCrystalReports() method enables users to interact with the report at runtime. ' It also controls programmatic interaction with the report. Private Sub ConfigureCrystalReports() Dim CRReport As ReportDocument
CRReport = New ReportDocument Dim reportPath As String = Server.MapPath("Reports/ProductNutritional.rpt")
'Loads a new report. If a report is already loaded, then it is closed and a new one is opened. CRReport.Load(reportPath)
'Don't allow the user to enter the login information CReportViewer.EnableDatabaseLogonPrompt = False
'Set up an object to use the connecton info Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
Dim sName As String = System.Configuration.ConfigurationManager.ConnectionStrings("ItemMasterConnectionString").Name
'Set the DatabaseName, UserID, and Password properties of the ConnectionInfo instance. myConnectionInfo.ServerName = "myserver" myConnectionInfo.DatabaseName = "ItemMaster" myConnectionInfo.UserID = "me" myConnectionInfo.Password = "mypassword"
'Enter a call to the SetDBLogonForReport() method, by passing in the ConnectionInfo instance and the NorthwindCustomers report. SetDBLogonForReport(myConnectionInfo, CRReport)
CRReport.SetParameterValue("parmItemNumber", "72012345")
CReportViewer.ReportSource = CRReport
End Sub
Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument) '************************************************************************** 'Copied from: http://msdn2.microsoft.com/en-us/library/ms227783(VS.80).aspx '**************************************************************************
'Tables is an indexed class that contains instances of the Table class. Dim myTables As Tables = myReportDocument.Database.Tables
'Create a foreach loop that loops through each Table instance in the Tables indexed class instance. For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
'Within the foreach loop, retrieve the TableLogonInfo instance from the LogOnInfo property of the Table instance. Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
'Within the foreach loop, set the ConnectionInfo property of TableLogonInfo to the ConnectionInfo parameter. myTableLogonInfo.ConnectionInfo = myConnectionInfo
'Within the foreach loop, pass the TableLogonInfo instance as a parameter to the ApplyLogonInfo method of the Table instance. myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
End Sub
End Class If you need more help, I just learned all this the last few weeks so it's fresh. Please ask. If anyone can tell me how to get the myConnectionInfo info out of my config file then I'll be grateful. I don't mean as separate ones, I mean using the connectionStrings one that has one long connection string. |
|