Dynamic SQL based Crystal Reports

A

Andrew

Hey all,

Been working with the Crystal Report Viewer, and have run into a situation I
am hoping someone can help me get past. This may be more of a CR question,
but hoping for some CR gurus to stop by in here.

Crystal's knowledgebase has made available a bunch of examples for both
ASP.Net and VB.Net applications for download and review (I added the links
at the end of this post). One of the examples is how to pass in a parameter
to the form from the .aspx page so you can alter what is displayed. However,
on closer inspection, you find that the form pulls across a huge set of
records and merely filters out all records not in the group matching the
parameter passed in.

My snag is that I do not want to pull across a huge set of records, rather I
would prefer to use a stored procedure on the SQL Server that accepts a
parameter and returns only those records I want. The records are the same
structure every time, just the content may be different. While the example
shows how to pass in the parameter, I do not know how to set up the form to
utilize not just a Stored Procedure, but rather one that requires a
parameter.

In short: Create an ASP.Net page that displays a Crystal Report whose data
is determined by a parameter passed in to the report and used in a Stored
Procedure tying it to a SQL Server.

Has anyone in here run into this situation and can explain how to deal with
it?

-- Andrew



Crystal Decisions Project Examples:
--------------------------------------------
VB .NET Web Sample Applications
http://support.businessobjects.com/communityCS/FilesAndUpdates/vbnet_web_samples.exe.asp

VB .NET Windows Sample Applications
http://support.businessobjects.com/communityCS/FilesAndUpdates/vbnet_win_samples.exe.asp
 
L

Lucas Tam

My snag is that I do not want to pull across a huge set of records,
rather I would prefer to use a stored procedure on the SQL Server that
accepts a parameter and returns only those records I want. The
records are the same structure every time, just the content may be
different. While the example shows how to pass in the parameter, I do
not know how to set up the form to utilize not just a Stored
Procedure, but rather one that requires a parameter.

Here is what I do:


1. Create an stored procedure

2. Create an ADO.NET Recordset (Add New Item -> Dataset) in Visual
Studios

3. Create a new Report - referecing the ADO.NET report

4. Fill the Dataset with the Report Data. Be sure to name the tables in
the Dataset - CR needs the proper dataset table names to load the data
properly.

5. Bind the dataset to the report.


BTW, you may want to use the System.reflection classes to create a
dynamic loader - that is what I do an works very well.
 
A

Andrew

Lucas Tam,

Thanks for the response and suggestions. I will go see if I can get
this to work...it sounds just like what I need to do. I smacked my forehead
for not thinking of it myself. :)
In the mean time -- and if you see this message -- if I could ask a
couple quick questions....

1) Do I have to use the GUI version (or "drag&drop" version) of the
ADO.Net Dataset, or can I use one coded by hand to bind to? I ask this
because I crerated a .Net DLL that handles all of my Dataset, DataReader, DB
Connectivity, etc., stuff (cuts down on the rewriting of code time) and
would like to use that if possible.

2) I am not quite sure I follow your suggestion of using the
System.Reflection classes. Are you saying to create a sub/function that
sets up the Dataset per passed in info prior to binding the CRViewer upon
page load? Or are you talking about something else? I figured to simply do
the former: read in some data passed through ah HTML Form or URL Item, set
up the Dataset's SQL statement from these, get the records, bind the report,
and view the page. If you are suggesting an alternate method, I am always
open to new ideas.

The usage of the CRViewer is still very new to me, as well as still
being fresh to .Net. I appreciate your help. Thanks again.

-- Andrew
 
L

Lucas Tam

1) Do I have to use the GUI version (or "drag&drop" version) of
the
ADO.Net Dataset, or can I use one coded by hand to bind to? I ask
this because I crerated a .Net DLL that handles all of my Dataset,
DataReader, DB Connectivity, etc., stuff (cuts down on the rewriting
of code time) and would like to use that if possible.

You use the GUI version to generate a Dataset. This dataset will be
referenced by Crystal Reports.

You will still need fill the dataset tho.

BTW, take a look at Microsoft's Data Building Blocks. Microsoft has
already written a set of classes to handle typical ADO.NET operations.
2) I am not quite sure I follow your suggestion of using the
System.Reflection classes. Are you saying to create a sub/function
that sets up the Dataset per passed in info prior to binding the
CRViewer upon page load? Or are you talking about something else? I
figured to simply do the former: read in some data passed through ah
HTML Form or URL Item, set up the Dataset's SQL statement from these,
get the records, bind the report, and view the page. If you are
suggesting an alternate method, I am always open to new ideas.

I'm using the System.Reflection classes to dynamically instantiate the
reports. I'm using the embedded version the reports - rather than
loading the reports off the disk, I am dynamically invoking a new
instance of each rpeort by calling the report's respective classes.

If this doesn't make sense to you, there are two ways of loading a CR
report. Either off a disk or by calling a report's classname and
instantiating it that way.

Reading off a disk is good if you wish to edit your reports often.
Instantiating a report via it's class name is good if you wish to embed
the reports inside the DLL and not have the report files exposed to the
outside world.
 
A

Andrew

You use the GUI version to generate a Dataset. This dataset will be
referenced by Crystal Reports.

You will still need fill the dataset tho.

Got it. Built a quickie test page, and everything runnning smoothly.
Thanks for the help on this one. Can't believe how quick and easy this
was....waiting for something to go wrong. :)
BTW, take a look at Microsoft's Data Building Blocks. Microsoft has
already written a set of classes to handle typical ADO.NET operations.

I will look into this, thanks for the heads up. :)

Instantiating a report via it's class name is good if you wish to embed
the reports inside the DLL and not have the report files exposed to the
outside world.

Ahhh, was doing this already, just didn't follow the way you were referring
to it. :)

Again, thanks for your help, and I hope I can ask you questions in the
future if I run into more snags.

-- Andrew
 

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

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top