Crystal reports paramaters

  • Thread starter Thread starter touf
  • Start date Start date
T

touf

hi,
I'm using Crystal reports to generate a simple report in a VB.net windows
application, I've defined all my stuffs (accessMDB,query, 2 parameters) in
the report design, and it's working fine, when a report is opened it prompts
me to input the parameters values .
But, in order to incorporate this report to my application, I have 3
quetions:
1- How can I send the parameters from my form directly (so there will be no
prompt)?
2- How can I use a dataset (that I define by code in my form) as datasource
of the report (as parameter??) ?
2- And/Or how can I send the connection object (or connection string) as
parameter ?

note: I've an Access2000 database, and I use a strongly typed report -
reportDocument - crystalReportViewer to display the report.

Thanks a lot for your help.
 
You can dynamically set the SelectionFormula property of the reportviewer
and incorporate your params there for instance. You can create a blank
dataset for instance and then base your report on the XML file, just select
it as the DataSource.

Not sure about the connection string. What do you need to do? I can
probably be of more help with number 3 if you let me know.

HTH,

Bill
 
Hi Touf,

Re parameters, here's some instructional code:
Dim paramFields As New ParameterFields()

Dim paramField As New ParameterField()

Dim discreteVal As New ParameterDiscreteValue()

paramField.ParameterFieldName = "selectedtable"

Select Case gl_browseprintvar ' this is a global variable in my app that
contains the name of the report

Case "f:\imcapps\retcatttable.rpt"

discreteVal.Value = "Retail Categories Table"

Case "f:\imcapps\vendortable.rpt"

discreteVal.Value = "Vendor Table"

Case "f:\imcapps\transittable.rpt"

discreteVal.Value = "Old/New BIPAD Translation Table"

End Select



paramField.ParameterFieldName = "selectedtable"

paramField.CurrentValues.Add(discreteVal)

paramFields.Add(paramField)

CrystalReportViewer1.ParameterFieldInfo = paramFields

All I'm doing here is passing a param that provides the translation for the
report parameter 'selectedtable', which is then displayed in the report as
part of the header.

HTH,

Bernie
 
Thanks Wiliam,
If i find a way to pass the dataset (question2) i dont need the question3
because I will send all the information from my form as dataset.
Can you please explain me more your suggestions ... give me the steps to
folow for this. can you specifiy for each question ( 1 and 2)

Thanks.
 
Hi touf,

this is actually pretty simple. let me try to walk you through the
process.

1.) define your data...

you'll need to define what your dataset is going to look like using an
xml schema file. They're relatively easy to create if you have any
experience with xml. add an xml schema file to your project and use
the xml schema designer in vs.net to define what your dataset is going
to look like.

2.) create your report...

once you have the xml schema file created to represent your dataset,
use it to create your report. Add a crystal report to your project
through the "add new item" project option. In the create new report
wizard, on the data tab select "More Data Sources" - "ADO.NET(XML)".
Point the dialog to the xml schema file you created - "mySchema.xsd"
etc. Then it will be just like creating your report using sql, oracle
or any other data soruce. you'll be able to drag and drop your dataset
fields onto your report etc.

** one note here ** if you decide to change the structure of your
dataset, be sure to update your xsd schema file and update your
report.

3.) when your report file is done, move on to writing your code to
generate your report from your application...

<code>

'--- dataset to hold your data ---'
Dim myData As DataSet
myData.ReadXmlSchema("c:\myDirectory\myReportSchema.xsd") <-- your
schema file
'--- code to populate your dataset ---'
'--- more code to populate your dataset ---'

Dim report As CrystalDecisions.CrystalReports.Engine.ReportDocument
report.Load("c:\myDirectory\myReport.rpt") <-- your report file

'--- set the datasource of your report file to your dataset ---'
report.SetDataSource(myData)

'--- set parameters ---'
Dim prmField As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
= report.DataDefinition.ParameterFields("myParameterFieldName") (watch
word wrap)

'--- create parameter value collection ---'
Dim prmValueCollection As New CrystalDecisions.Shared.ParameterValues

'--- create object to hold parameter value ---'
Dim prmValue As New CrystalDecisions.Shared.ParameterDiscreteValue

prmValue.Value = "myParameterValue"
prmValueCollection.Add(prmValue)

prmField.ApplyCurrentValues(prmValueCollection)

</code>

this code isn't tested, I'm just puting it together from memory.

of course, your parameter value has to be of the same type as the
parameter defined in your report.

the only downside i experienced creating my project this was that you
can't preview your report with data. since you are creating your
report based off of an xsd schema there is no data to preview. But
this is easily worked around by creating a small viewer application
that uses the crystal reports viewer control.

good luck!

here's a link to a great online reference for creating cr.net
applications by brian bischoff. it helped me greatly when i was first
trying to work my way
through this.

http://www.crystalreportsbook.com/Chapters.asp


jim
 
Back
Top