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? :)