Crystal Reports and Datasets

azcegarman

Member
Joined
May 5, 2005
Messages
9
Location
Arizona
Hi,

Let me preface this by stating I am a "noob" to VB.Net.

I have a series of reports I am in the process of creating using Crystal Reports (yes, this is also a first time event .. such fun!!). THe question I have is one that I have looked through the forums for a clear (to me) answer
yet havent found one yet.

I have an MS Access application that runs in disconnected mode using a dataset for all data manipulation events. I would like to reference that dataset with Crystal Reports and not have to define a second dataset just for that purpose.
The reasons for using a dataset are two-fold:
First to allow the Crystal Reports to run without being tied to a specific location
Second to insure that the reports are using the most current version of the data being worked with

I wish to keep the degree of complexity down as much as possible thus the interest in using an existing dataset as opposed to creating and maintaining a new dataset.

Is there a way to do that?
If so, could someone provide a detailed explanation for doing this?
If there isnt a way to using a pre-defined dataset, I would appreciate any suggestions on the steps and procedures for the addition of a second dataset.

Thanks!
 
If you plan on using the same dataset for more than one operation than you should call Dataset.clear() before using it...
Now back to crystal reports:

Code:
Dim DaReport as new sqlDataAdapter(sqlCommand,SqlConnection)
DaReport.Fill(Dataset)

ReportDocument.SetDataSource(Dataset.Tables(0))  Make sure you dont forget      that Tables(0)
CrystalViewer1.ReportSource=ReportDocument

When you create the report document and choose your database do not select a table, select "command" and you should enter a query that would return the same columns as the SqlCommand used for the DataAdapter
Cheers
 
Puiu said:
If you plan on using the same dataset for more than one operation than you should call Dataset.clear() before using it...
Now back to crystal reports:

Code:
Dim DaReport as new sqlDataAdapter(sqlCommand,SqlConnection)
DaReport.Fill(Dataset)

ReportDocument.SetDataSource(Dataset.Tables(0))  Make sure you dont forget      that Tables(0)
CrystalViewer1.ReportSource=ReportDocument

When you create the report document and choose your database do not select a table, select "command" and you should enter a query that would return the same columns as the SqlCommand used for the DataAdapter
Cheers

Hi Puiu,

First, Thanks for the response and the information :)

Now, a bit more information on the existing dataset so I am sure I understand how this will work. The table(0) identifier is used to point to the table currently existing in the dataset. Would I be correct in assuming that the code you have provided is set for a single table dataset? Why the question? The existing dataset I use in this project contains all of the active tables used by the system at any single point in time. However, that does not guarantee that the required table is present in the dataset which means I will need to load that table when I need the information for the report.

That being said, I will be using your code to work on the reports and anticipate no problems IF I use the code correctly. :-\

This brings another question to mind: Would I be better served to create a seperate dataset and dataadapter as part of an inherited(sp) form thereby providing the dataset (and associated tables) to Crystal reports at design time? The dataset would be pointed at the tables located on the hard drive.
And in this particular instance, works out given that the dataset will contain all data including unsaved updates which I wish to avoid.

Your thoughts :)

Thanks!
 
The table 0 is the table obtained with the sql command in my example.
I would recomend you use a new dataset..honestly i think it would be easier

I stated in my post that u should use dataset.clear before you fill the dataset with the data for the report, but this will clear the data that was stored in the dataset.
If you really want to use the same dataset and not clear the data already in it(not using dataset.clear), i think u could use something like:

DataAdapter.fill(Dataset,"MyTable")
....
ReportDocument.SetDataSource(Dataset.Tables("MyTable"))

I havent tried this before, so I dont know what results it would return...I guess they should be the same
 
Back
Top