I have a crystal report with several parts
Page Header a (Company Information)
Page Header b (Sub-Report: has list of specific countries)
Page Header c (Sub-Report: has list of specific Products)
Page Header d (Sub-Report: has list of specific items)
The data source of the report is given by a Dataset "DS1" through C# Application (Push Method)
Because of the complex logic in the background, it is decided to have Dataset "DS1" with 4 Data tables (tbl0,tbl1,tbl2,tbl3) to hold separately the correct data in the Dataset.
The dataset doesn't have any relationships, because I have loaded directly the final data result in the relative Data Tables in the Dataset
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
DataTable dt3 = new DataTable();
DataTable dt4 = new DataTable();
Load_CompanyInfo(country_ID, ref dt1);
Load_Countries(_ApprovalID, ref dt2);
Load_Products(_ApprovalID, ref dt3);
Load_Items(_ApprovalID, ref dt4);
_ds_tmp.Tables.Add(dt1);
_ds_tmp.Tables.Add(dt2);
_ds_tmp.Tables.Add(dt3);
_ds_tmp.Tables.Add(dt4);
In the Form ReportView.cs, I have assigned the Dataset to the report.
rep_c_single.SetDataSource(ds.Tables[0]); // Main company info
rep_c_single.Subreports[0].SetDataSource(ds.Tables[1]); // countries
rep_c_single.Subreports[1].SetDataSource(ds.Tables[2]); // products
rep_c_single.Subreports[2].SetDataSource(ds.Tables[3]); // items
rep_c_single.Refresh();
cr_Viewer.ReportSource = rep_c_single;
on the report file, the sub reports doesn't have link field to the main report.
Because final Data is prepared in the Data Tables.
I just want to display the Data in the Sub report independent from the Main Report data source.
What I have till now, the sub reports lists all countries and all products, not what in the data table exists.
EDIT:
It is important to mention: the sub reports and main reports don't have any relations. I want only to PUSH data to the relative Sub-reports
thanks for any help
i'm not entirely sure.. but i've done this once..
make sure your report has a group based on the primary key of the main report (with which you want to link all the sub reports)
right click on the sub report
change sub report links
in the available fields select the column name of the sub report or respective data table
click on add to add it into the fields to link
it'll also show in the sub-report paramater to use drop down list underneath
check the flag -- select data in sub-report based on field
select the main report primary key group you made in the first step
Hope it works.. :)
Related
I try to get 2 subreports in my main report.
The subreports works separately but don't work together.
My main report:
I want it to look like this, but the lines are broken when it is too much.
Müşteri Hizmet Kayıtları
"Müşteri Hizmet Kayıtları" sub-report looks correct, but then comes to the front and end of "Müşteri Ödeme Kayıtları" sub-report.
It works without problems when the row number is small but it gets broken like this when the number of rows is large.
My codes:
DataTable dt = _datab.TableDataTable($"SELECT * FROM CariHizmetbyCari where CariId={_cari.CariId}");
DataTable dt2 = _datab.TableDataTable($"SELECT * FROM CariMuhasebebyCariHizmetId where CariId={_cari.CariId}");
DataSet dataSet = new DataSet();
dataSet.Tables.Add(dt);
dataSet.Tables.Add(dt2);
rptCariTotal rptCariTotal = new rptCariTotal();
rptCariTotal.Database.Tables[0].SetDataSource(dataSet.Tables[0]);
rptCariTotal.Database.Tables[1].SetDataSource(dataSet.Tables[1]);
rptCariTotal.SetParameterValue("pAdSoyad", _cari.CariAdı);
rptCariTotal.SetParameterValue("pMail", _cari.Mail);
rptCariTotal.SetParameterValue("pTelefon", _cari.Telefon);
rptCariTotal.SetParameterValue("pWebSite", _cari.WebSite);
crvViewer.ReportSource = rptCariTotal;
crvViewer.Refresh();
You can't have that first sub-report in Page Header.
Create two detail sections ( Right Click on Detail - Insert Section below) and set each sub report in each one.
I have a crystal report rpt report created with some fixed fields that fill with a datatable, the fields obtained in the datatable may vary depending on the SQL statement of the fields in a form. Therefore, the question is whether in the design of the rpt form I can add, by code, new fields obtained in the datatable. For example, in the datatable I get the First and Last Name fields, and I show them in the report (in the design I have inserted the First and Last Name fields). Now in the datatable I get Name, Surname and Telephone, if I call the same report, it will fill in only Name and Surname, the Telephone field, not being inserted in the report will not appear, the idea is to add it. I am filling the dataset in such a way:
DataSet ds = new dsDataSet();
ds.Tables.Add(new DataTable());
foreach (DataColumn column in dtBusqueda.Columns)
{
ds.Tables[0].Columns.Add(column.ColumnName);
}
Now it would be those dataset fields to insert into the report as I explained before. The report is loaded as follows:
ReportDocument Report = new ReportDocument();
Report.Load("../../crReporte.rpt");
Report.SetDataSource(dtDataTable);
frmReportes form = new frmReportes(Report);
form.Show();
Thanks.
Crystal work only with pre-defined data object to display the data in a specified format. So if you pass a different data object then it will give you errors that it cannot locate your column.
I can offer :
1) Use same dataTable source for all (put tel column in original). So set visibility on Crystal Report for your special column. with supress.
2) You can create individual 2 different report And in your If Case you can load another report template if you want.
if it is only tel number not for complex requirement. use way 1. just set visibility.
But if you have complex requirement. I think you should use 2 different report template.
I'm trying to show a report of all vouchers uploaded to the DB. This report contains 2 datasets; voucherSummary and voucherHeader. Every voucher has a header and a summary. Is it possible for me to pass multiple instances of these datasets to the same report, and display each instance on a new page as a new voucher?
I've tried using a foreach loop to add new datasources for the 2 datasets, but it comes up blank when running the program.
foreach (VoucherUploadModel model in models) {
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dsVoucherUploadSummary", model.GetVoucherDetailsUploadSummary()));
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dsVoucherUploadHeader", model.GetVoucherUploadHeader()));
//ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dsUserInfo", VoucherUpload.Core.CommitDocumentSetHelper.GetUserInfo()));
}
I want to print a report based on the datasource list of a DataGridView.
I want to use Rdlc reports for this. I created the report, put a tablix in it with a DataSet named "DataSet".
Then, in the report viewer, I just delete that DataSet, and add a DataSet with the same name that contains the list(IEnumerable) I wanted. The problem is that the Tablix is not showing anything. I looked in the internet but can´t find anything related to it. Also, how can I make fields visible or invisible using the ReportViewer?
This is my code (it is in the Form´s Load event:
Sistema_financiero_Entities db = new Sistema_financiero_Entities();
IEnumerable<Cheque> cheques = db.Cheque.Where(x => x.id_cheque != 6).ToList();
ReportDataSource data = new ReportDataSource("DataSet", cheques);
try
{
this.rpt_Viewer.LocalReport.DataSources.Add(data);
this.rpt_Viewer.RefreshReport();
}
Some considerations: db is the Entity framework object context. cheques is the list (in this example I´m just taking data from the db, but I will use the DataGridView datasource list, I did this just to test if this was working). rpt_Viewer is the reportViewer.
Changing IEnumerable<Cheque> cheques = db.Cheque.Where(x => x.id_cheque != 6).ToList();
to
List<Cheque> cheques = db.Cheque.Where(x => x.id_cheque != 6).ToList(); worked perfectly.
I'm still new to C# and reports, and in order to take baby steps, I started with a Crystal Report using one table.
Eventually I figured it out and it worked brilliantly.
Then I added another table to the report. I haven't changed anything in my code. Adding a field from the second table to the report, results in a blank report.
Removing that field again (so no columns form the second table is on the report), the report produces data again.
So I get the impression that the problem is on the report side. But I have included the code anyway:
private void Load_Ord_Rep()
{
using (MySqlConnection conn = new MySqlConnection(OTW.Properties.Settings.Default.wcdbConnectionString))
{
conn.Open();
String sql = "SELECT * FROM wcdb.order_table, wcdb.mat_table WHERE order_no = '13661' and order_table.mat_code = mat_table.mat_code";
using (MySqlCommand cmdSel = new MySqlCommand(sql, conn))
{
DataSet ds = new DataSet();
MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
da.Fill(ds);
ReportDocument rpt = new ReportDocument();
rpt.Load("C:\\Visual Studio 2008\\Projects\\OTW\\OTW\\CrystalReport3.rpt");
dataView1.Table = ds.Tables[0];
rpt.SetDataSource(dataView1);
crystalReportViewer1.ReportSource = rpt;
crystalReportViewer1.Refresh();
}
conn.Close();
}
}
With further investigation I have come to the conclusion the problem is not the code or the link, but rather the loading of the second table. I did a outer join with the values being equal or greater. Only the first table's results are displayed on the report. So because the second table's values are not read, no join can be established between the two tables and thus no data on the report. Now the question: why is the second table not being read by Crystal Report!?
UPDATE
I removed the second table from the main report and added a sub-report with the data. Same result as before. The sup report shows blank. Running the sup report on its own (as the main report), it populated correctly. I'm using MySQL, could it then maybe be a database issue?
UPDATE
I created a new app, this time connected the report to the database using ODBC (instead of ADO.NET). And it worked perrrfect. Now to figure out why ADO.Net is not working....as my entire program is based on it.
You don't need to do any of the code you are doing with the dataset/dataview. I recommend you allow the report to "pull" data (you are "pushing" data to the report now).
To pull data requires only the following:
ReportDocument rpt = new ReportDocument();
rpt.Load("C:\\Visual Studio 2008\\Projects\\OTW\\OTW\\CrystalReport3.rpt");
rpt.SetDataBaseLogon("userName", "password", "servername", "database");
crystalReportViewer1.ReportSource = rpt;
This reduces the risk that you're confusing the report up by passing in a dataview that it has no idea how to map to the tables you added while designing the report. (Which I'm 99.999% sure is happening now.)
All the code above lacks is parameters if you had any that needed to be set. It looks like you may be trying to "push" data because you wanted to filter on that order number or something? If that is the case, add a 'record selection formula' inside your report, base it's 'where' aspect of that formula on a Crystal Report parameter and add a rpt.SetParameter(arguments) line to the code I provided.
No this is not a licensing constraint, I'm certain of that.
Successful troubleshooting path:
1) Used the simple code to load the report:
* No errors, but no data in the report
2) Played with join options in the report:
* Also resulted in a blank report, even with only one table
* Concerned the second table is not reading data
3) Checked for record filtering by a 'record selection formula' which might limit/prevent rows from being returned
* In this case, wasn't applicable
4) Analyzed how joins were being done:
["It's probably how you are joining. For example: if you do a right outer join to a second table and it has no data, then even the first table's rows won't come back."]
A join was done on the primary id field (mat_code) in the 'orders' table to the same field (mat_code) in the second table, 'material'. This seemed fine.
Attempted a Left Outer join with the link type being ">=". The report printed the first table (orders) with data. But still none of the second tables' (material) data.
Made a new report, this time first adding the "second" table (material) and then the first (orders). This time with an outer join, and only the material table shows data. In other words, it only appears to pull data for the first, or primary table, then stops.
5) Attempted loading the second table's data by putting it into a subreport, and linking the subreport on the same 'mat_code' field:
(Helpful tutorial: http://vb.net-informations.com/crystal-report/vb.net_crystal_report_subreport.htm)
Sub-report also shows blank. Only the main report works. Whatever table exists in the subreport is not being populated.
Still sees no data using the simple suggested code, his original code still shows the first table's data
6) Check for a mismatch between the table's connection and definition, and the actual data structure/contents being submitted to, or loaded by, the report. A specific test was suggested, go to:
i) 'Set Database Location' (where you manage tables for the report)
ii) Look to see if an XML/DataSet was used versus OLEDB was done
iii) Change the database table location to the same tables, but with an OLEDB connection type (repeat for all tables)
When attempting above, when the 'Update' button was hit, the screen just flickered for a split second, but showed no message. After testing the report again, still no change in behavior. He was using ADO.NET to connect to the data.
7) Still highly suspicious of the data table definition and connection type. Suggested the following test:
i) Make a brand new 1 page application with only simple test code.
ii) Make a new report with only the 'orders' and 'materials' tables, using OLEDB from the beginning
iii) Add only the mat_code field from the main table to the report
iv) Add a subreport for 'materials' linked on mat_code
v) Show only mat_code on the subreport
vi) Run the app
If data shows, the problem is either:
Answer 1: A mismatch between the database definition (as was read when the report was FIRST made, and connected via ADO.NET to the tables) and the actual data table/column definitions being found when loading the report later (i.e. Someone edited the 'materials' table to change a column definition, or the number of fields, etc.)
Answer 2: Possible defect in the particular combination of Crystal Reports and Windows drivers required to push ADO.NET data to the report. Using the pull-data model over OLEDB may be working around something issues. Those issues may be addressed with the latest Crystal Reports and/or Windows drivers (i.e. hotfixes or Windows updates, driver packs, etc.)
The test worked fine. Even without making a subreport. The data pulled in just like it was supposed to.
Check the link between the two tables in crystal reports. Are they as what you expect ?
Check it by
Field Explorer> DataBaseFields > (RightClick) DatabaseExpert > (See Tab) Links