Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I just wanted to say THANKS for the forum. The knowledge I gain from your site is invaluable..."

Geography

Where in the world do Tek-Tips members come from?
bburnell (Programmer)
9 Nov 07 10:17
Hi all,

Anyone know where I can find good sample code for:

A) Showing a Crystal Report in asp.net via vb.net

B) Passing a parameter to said Crystal Report (programatically)

C) Exporting said Crystal Report to pdf programatically.

All of the examples I have or have seen do not seem to work in 2005 or have obsolete methods in 2005.

Any help would be greatly appreciated!
~Brett
bburnell (Programmer)
9 Nov 07 12:42
Ok. I got it. B is done with the following:
crReportDocument.SetParameterValue(<index#>, <value>)

~Brett
Helpful Member!  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.

CODE

Partial 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.



bburnell (Programmer)
30 Nov 07 14:51
If anyone can tell me how to get the myConnectionInfo info out of my config file then I'll be grateful.

Do you mean like this?
ServerName = configurationAppSettings.GetValue("ServerName")
UserID = configurationAppSettings.GetValue("UserID")
Password = configurationAppSettings.GetValue("Password")

For a connection string, you just put the whole DSN in a variable name in your web.config file and call it like any other variable name.

SavedDSN = configurationAppSettings.GetValue("YourDSN")

~Brett

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close