Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > Crystal Reports
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Crystal Reports General discussion about Crystal Reports. For discussions specific to the book Professional Crystal Reports for VS.NET, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Crystal Reports section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 8th, 2005, 07:10 AM
Authorized User
 
Join Date: Sep 2004
Location: ctl, ke, India.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ctranjith
Default Passing values to Crystal Report

Sir
 I am using vb.net and crystal report . I want to pass one text (say company name) directly to report (not through any database field)
Could you please tell me how it is possible



Reply With Quote
  #2 (permalink)  
Old February 21st, 2005, 04:55 AM
Registered User
 
Join Date: Feb 2005
Location: , , India.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

U can solve it by using two methods.
1)Using Parameter Field.Add new parameter to report and set its value to
text(company name) in your report viewer containing file(.vb).
2)Using Report Title.Set value which you want to display on report to that parameter in your code behind .vb page on which report viewer is located.
In this way u can assign default value as well as value which can be dynamically changed.

Reply With Quote
  #3 (permalink)  
Old February 26th, 2005, 02:35 AM
Registered User
 
Join Date: Feb 2005
Location: Surat, Gujarat, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can programmatically pass parameter values into your Crystal Report using VB.NET code similar to this:
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    '
    ' Load the selected report file.
    '
    Dim CR As New ReportDocument
    CR.Load(strReportPath)
    '
    ' Declare the parameter related objects.
    '
    Dim crParameterDiscreteValue As ParameterDiscreteValue
    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    Dim crParameterFieldLocation As ParameterFieldDefinition
    Dim crParameterValues As ParameterValues
    '
    ' Get the report's parameters collection.
    '
    crParameterFieldDefinitions = CR.DataDefinition.ParameterFields
    '
    ' Set the first parameter
    ' - Get the parameter, tell it to use the current values vs default value.
    ' - Tell it the parameter contains 1 discrete value vs multiple values.
    ' - Set the parameter's value.
    ' - Add it and apply it.
    ' - Repeat these statements for each parameter.
    '
    crParameterFieldLocation = crParameterFieldDefinitions.Item("StartDate")
    crParameterValues = crParameterFieldLocation.CurrentValues
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
    crParameterDiscreteValue.Value = strStartDate
    crParameterValues.Add(crParameterDiscreteValue)
    crParameterFieldLocation.ApplyCurrentValues(crPara meterValues)
    '
    ' Set the Crytal Report Viewer control's source to the report document.
    '
    CrystalReportViewer.ReportSource = CR
If your report's DataSource is a .NET DLL DO NOT set the ReportDocument's DataSource property programatically as in the code below. However, if the DataSource is an XML Schema (.xsd) file you must set it prior to setting your parameters.
    cr.SetDataSource(DS.Tables("Customer"))
If your report's DataSource is a .NET DLL as shown here and the public functions that return the datatables available to your report where changed to require parameters, as illustrated below, the parameters can be set as just described.
    Public Function Customers(theStartDate As String) As DataTable
If the parameters were added to your Crystal Report by clicking the Parameter Fields node in the Crystal IDE's Field Explorer they can be set using the following code:
    Dim cr As New ReportDocument
    cr.Load(strReportPath)
    cr.SetDataSource(DS.Tables("Customers"))
    cr.SetParameterValue("StartDate", strMyParmValue)
    CrystalReportViewer.ReportSource = cr

Quote:
quote:Originally posted by ctranjith
 Sir
I am using vb.net and crystal report . I want to pass one text (say company name) directly to report (not through any database field)
Could you please tell me how it is possible



Reply With Quote
  #4 (permalink)  
Old February 28th, 2005, 03:52 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

i'm a CR noobie here, still don't understand about this:
crParameterFieldDefinitions.Item("StartDate")

How am I going to set the field in the CR having StartDate?
I inserted a Text Object in CR, i input with text; StartDate or even tried to change the name for the Text Object as StartDate, also will get the Invalid field error after Build.

do i need to include special character like {}, []; eg. {StartDate} in the CR, but even so the VS.NET still have build error 'coz it couldn't find the StartDate field in the CR still. - I have set the connection path as CR.Load(Server.MapPath("form1.rpt")), where form1.rpt resides in the root folder of my Application, anything wrong here? (doesn't have any build error)

I'm using VS2003.NET & CR 9.1.5


Any advice
Reply With Quote
  #5 (permalink)  
Old March 2nd, 2005, 01:20 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After explore more into CR.NET, i insert a New parameter field from field explorer this time instead of text object used previously.

I've set Name as StartDate, value type as String, Checked discrete value. Then i click ok & drag drop the field into the report. After I saved this form1.rpt & do a Build, there's this error:

Exception Details: CrystalDecisions.CrystalReports.Engine.ParameterFi eldCurrentValueException: Missing parameter field current value.


how could i set current value to the parameter field i created? or maybe the whole steps r wrong? Pls kindly advice.




Reply With Quote
  #6 (permalink)  
Old March 2nd, 2005, 03:56 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

after bashing head on walls numerous times, i've found out the reason why i couldn't pass the value to CR

in case you'll like to know, it's due to wrong declartion for my reportdocument. :D

Reply With Quote
  #7 (permalink)  
Old April 6th, 2005, 04:52 AM
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to SKILITES
Default

Hi 2 power ,
Tyr this .and let me know if it works...
Abc is the name of the parameter you created on your CR.
and on your CR you need to set the value for the parameter field in select expert
ABC = {?ABC}
Try n see if this works.otherwise let me know.

************************************************** **************
Dim param1Fields As New CrystalDecisions.Shared.ParameterFields()
Dim param1Field As New CrystalDecisions.Shared.ParameterField()
Dim param1Range As New CrystalDecisions.Shared.ParameterDiscreteValue()
            param1Field.ParameterFieldName = "ABC"
            param1Range.Value = 1
            param1Field.CurrentValues.Add(param1Range)
            param1Fields.Add(param1Field)
            CrystalReportViewer1.ParameterFieldInfo = param1Fields
Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocum ent()
CrystalReportViewer1.ReportSource = new() YOUR REPORT NAME()
            CrystalReportViewer1.Refresh()


Reply With Quote
  #8 (permalink)  
Old March 24th, 2006, 12:22 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Big Bro
Default

Hello,

I am so stuck here. I have used the following code. The problem is when I run the program it always prompt me to enter the "Parameter Value" eventhough I passed through my VB.Net application and I don't want that. When I pass value on that windows it grabs the data as per passed value. It doesn't allow me to pass value through programatically.

Please help me in this case. Your help is so appreciated.

************************************************** **************
Dim param1Fields As New CrystalDecisions.Shared.ParameterFields()
Dim param1Field As New CrystalDecisions.Shared.ParameterField()
Dim param1Range As New CrystalDecisions.Shared.ParameterDiscreteValue()
param1Field.ParameterFieldName = "ABC"
param1Range.Value = "any value"
param1Field.CurrentValues.Add(param1Range)
param1Fields.Add(param1Field)
CrystalReportViewer1.ParameterFieldInfo = param1Fields

Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocum ent()
CrystalReportViewer1.ReportSource = new() YOUR REPORT NAME()
CrystalReportViewer1.Refresh()

Reply With Quote
  #9 (permalink)  
Old March 27th, 2006, 01:23 AM
Authorized User
 
Join Date: Sep 2005
Location: Hydrabad, AP, India.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to vijaykumartaduri Send a message via Yahoo to vijaykumartaduri
Default

Hi,

In Windows application refresh() method is not required. Replace last 3 lines with this below code.

Dim rpt As New YOUR REPORT NAME
CrystalReportViewer1.ReportSource = rpt




Reply With Quote
  #10 (permalink)  
Old November 9th, 2012, 02:06 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks

Simpy removing the refresh method call solved the problem
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing value from winform to crystal report shai Crystal Reports 0 January 20th, 2007 05:19 AM
Passing values direct to data report without shlsoft VB Databases Basics 0 November 6th, 2006 07:51 AM
passing parameter values to the crystal report connect2sandep Crystal Reports 0 December 20th, 2005 06:27 AM
Crystal report, passing parameter suni_kutty Crystal Reports 2 October 7th, 2004 03:13 AM



All times are GMT -4. The time now is 06:07 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.