Add hoc Reports

H

Hadeel

Hi,

I'm trying to develop Dynamic reports (Add Hoc Reports) in Windows
application using VB.Net and .Net crystal Reports ( ver. 9). The user will
choose the fields he/she wants to view in the report and choose the group or
sorting field, and depending on that I will view the right fields in the
report. So I want to bind the report to a data set at RunTime , and then If
possible I want to save the report template to be viewed any time later. I
tried to use formulas in the report and then assign their values at runtime,
but it seems I'm missing some thing, because it is not working properly.
This is the code I'm adding to the form that has the Crystal report viewer ,
right after the InitializeComponent() function :





Dim crFormulaTextField1 As FormulaFieldDefinition

Dim crFormulaTextField2 As FormulaFieldDefinition

Dim crFormulaDBField1 As FormulaFieldDefinition

Dim crformulaDBField2 As FormulaFieldDefinition



Dim ds As DataSet

Dim dt As DataTable



'Field1 & Field2 are the fields the user wants to view in the 'report



ds = dsCreateDataSet("SELECT " & Field1 & "," & Field2 & "," from " &
TableName & "") ' This function returns a dataset



dt = tblCreateDataTable("SELECt " & Field1 & "," & Field2 & from " &
TableName & "") 'This function returns a datatable





crFormulas = Rpt.DataDefinition.FormulaFields



crFormulaDBField1 = crFormulas.Item(0)

crformulaDBField2 = crFormulas.Item(1)



crFormulaTextField1 = crFormulas.Item(2)

crFormulaTextField2 = crFormulas.Item(3)



'The errors start here

' pass in the database fields to be displayed

crFormulaDBField1.Text = dt.Rows(0).Item("" & Field1 & "")

crformulaDBField2.Text = dt.Rows(0).Item("" & Field2 & "")





Rpt.SetDataSource(ds)



CrystalReportViewer1.ReportSource = Rpt



I would reall appreciate your help.



Thanks in advance :)
 
P

Pete Davis

What you probably want to do is use the Crystal Reports report builder stuff
to build the reports dynamically. I haven't done this in .NET and I don't
know if it comes with the version of Crystal Reports that ships with
DevStudio. But basically, you lay out the reports using the API. You place
all your text labels and fields and stuff and then at run-time, you
dynamically assign the data.

I wish I could provide more specifics, but I no longer have access to the
Crystal manuals nor the code that I wrote to use it. Essentially the code I
wrote was a simplified report builder (simplified compared to crystal) that
let users choose the fields they wanted, how they wanted them labeled,
whether they wanted any calculations (sums, std. deviations, etc), and so
forth. Then I built the report at runtime.

You may want to check out the Crystal Reports support web site to find out
more information on how to do this.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top