views:

52

answers:

2

Hello everyone,

I have an application which needs to generate a report. However, I do not know how to generate a report using CrystalReport which is based on a query. Let's say I just need to generate report from my database which shows the values returned by my select query. I've never used Crystal Reports before so I'm new to this.

Thanks everyone :)

EDIT:

So far, this is what I have:

ConnectionString myConnString = new ConnectionString();
string connString = myConnString.getConnectionString();
SqlConnection connSearch = new SqlConnection(connString);
connSearch.Open();

SqlCommand cmdLoad = new SqlCommand("Search", connSearch);
cmdLoad.CommandType = CommandType.StoredProcedure;

cmdLoad.Parameters.Add(new SqlParameter("@AccountID", currentUser));
cmdLoad.Parameters.Add(new SqlParameter("@PeriodID", " "));
cmdLoad.Parameters.Add(new SqlParameter("@PriceID", " "));
cmdLoad.Parameters.Add(new SqlParameter("@ExpenseID", " "));
cmdLoad.Parameters.Add(new SqlParameter("@InventoryID", " "));
cmdLoad.Parameters.Add(new SqlParameter("@ProductInID", " "));
cmdLoad.Parameters.Add(new SqlParameter("@ProductOutID", " "));
cmdLoad.Parameters.Add(new SqlParameter("@PeriodMonth", periodMonth.Trim().ToUpper()));
cmdLoad.Parameters.Add(new SqlParameter("@PeriodYear", periodYear));

SqlDataReader read = cmdLoad.ExecuteReader();

DataSet ds = new DataSet();
DataTable dt = new DataTable("Results");
ds.Tables.Add(dt);
ds.Load(read, LoadOption.PreserveChanges, ds.Tables[0]);


CrystalReport1 crystal = new CrystalReport1();
crystal.SetDataSource(ds);
crystalReportViewer1.ReportSource = crystal;

connSearch.Close();
connSearch.Dispose();

However, there seems to be something wrong here since it always produce an exception saying that the report has no tables pointing to the crystal.SetDataSource(ds); line.

Anybody help me please? :)

A: 

Ok, it's not really an answer, but my advice is dump Crystal Reports before you get in any deeper.... it's just a world of pain.

Create your own reports in HTML, export to excel is trivial and there are free tools to export to PDF if you need to, you can even use the .Net charting.

.Net gives you all the tools you need to generate reports, the learning curve is probably not much greater and the control you end up with is massively greater.

James Gaunt
+1  A: 

Crystal Reports is a very capable tool and widely used in offices around the world. You are definitely doing yourself a favor getting familiar with it... and when you are, it is actually quite easy to use. :)

CrystalReportViewer will generate a user friendly interface and give you the ability to export your reports into all commonly used format.

To answer your question:

.Net only gives you the ability to build and view reports just as you would in a Crystal Report Client except that you can do it via the codebehind.

If I were you I would read through the white papers and familiarize myself with reporting first a little.

I think in your case the error might be referring to that, although you have assigned a dataset as datasource to your report there might be no table in the dataset or you haven't selected any fields to show in the report.

Try to debug the dataset before you bind it to the report and check whether the table is present.

G Berdal