Im setting the report datasource in my C# code like this:
report.SetDataSource(dataSource);
And it all works but after that the crystal report still tries to connect to the database.
I though that if i set the datasource from the code the report wont want to get more data from database then.
Is that really like so that even after setting the datasource from code report goes and asks more data from database?
EDIT: The real problem im facing is that i have 2 reports, one goes and fetches data from database after setting datasource from code and the other just doesn't. I have been pulling my hear all day to figure this out and no luck yet. The two reports are allmost identical, both use a database View to get the fields from database and both use the same code to set the datasource from code.
The logic is that i load the report in my code, get the required database fields from it and create DataTable with those fields. Then i fill it with data and set it as datasource with this: report.SetDataSource(dataSource);. For both reports the code and logic is identical! Just the fields are different..
In case if you have subreports.
loop through subreports
and call SetDataSource(dataSource) on each subreport object.
Report.RicevutaCup r = new Report.RicevutaCup();
System.Data.DataSet ds = CupDatasetFactory.CreaRicevutaCupDataSet(df);
r.OpenSubreport("RicevutaCup_Prestazioni").SetDataSource(ds);
r.SetDataSource(ds);
Solved my issue (after restarting IIS).
Related
My report gets data from a stored procedure. Two of the six parameters are dates (toDate and fromDate.) I integrate the report with C# Winforms and I pass the parameters through code the code with:
reportDocument.setParamterValue(0,paramValue);
The report works fine but does not render data despite showing the column header properly. When I refresh the report, it pops up the parameter window again. When I enter the parameters through that window the data shows, including column headers. But it doesn't work when I pass parameters through code.
How can I resolve this?
It looks like this:
CRPT.SetParameterValue("smonth", Servercls.month);
See this link for more info.
I suggest first of all call procedure in c# environment and save result in datatable and then send datatable to crystal report.
I found the error.
First it was not working with setting parameters through indexing. so i set the parameters through name as reds suggested.
second i was missing the parameters binding with report viewer object.
so i added the following line and it worked
crystalReportViewer.ParameterField.addRange(reportDocument.ParameterFields);
Thanks for the answers guys.
I need to show data on crystal report, my tables are as below
ClientServiceMaster (ServiceNo, ComplainDate, AttainDate, Counter)
ServiceDetail(ServiceNo, Problem, Reason, Action)
ReplacementDetail (ServiceNo, ItemNo, Qty)
Here ClientServiceMaster Data is only once, so I have kept that in Page Header
But there would be more then one records for ServiceDetail as well as ReplacementDetail, I want to show each rows of these both tables.
Kindly Help me in which section I need to add these tables and how to write code
Khilen
You should use sub reports.
You can use separate queries with datasets with the relevant data.
Here are some samples.. Hope you'll find something...
http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-subreports.htm
http://www.dotnetspider.com/resources/43691-How-create-sub-reports-crystal-report.aspx
I'm asking about a problem with C# and Visual Studio 2012; I'm trying to resize a column of a table in my database, effect with the dataTableAdapter on a Dataset.xsd
I'm using DataTableAdapter from a stored procedure with a SELECT statement to populate a DataGridView, reports and many more.
I created the table long time ago, but now there is an a problem with it.
I had to increase the length of a column and I changed the appropriate column length of the DataTable also. But it didn't give me the solution. still whenever I Fill or Get data through that DataTableAdapter it response with the previous (original) size of the column.
But when I create a new DataTable and redirect my code to the new DataTableAdapter, it works.
Why is this happening ?
Because redirecting code to the new DataTableAdapter is little bit difficult because I don't know all the places it use in the entire solution.
And also if can please tell me how to add new column to the table and deal with the DataTableAdapter with it also.
Thanks and waiting for your reply.
after doing small research with my friends , i got an proper way to fix this error.
not even re-sizing, but also any other change with the database Table or storedprocedure you have to reconfigure the dataTableAdaptor, unless it just work as , when it was created.
it will continue with major errors or sometimes, it will function incorrectly, even you cant figure out there is an error.
so whenever you do any change with the database Table or storedprocedure go to the dataSet.xsd , where the dataTable locate and right on the dataTable , then configure it again.
this saved me and worked.
I am new to this tool, so I do not know how I can get the data of a class and show in a report.
I don't have a database, my info is stored inside variables inside classes. Like this (Folder Objetos):
My program does: Read a XML, validate with XSD, serialize in this classes.
What I want: Take that information and show in a report.
It is possible to put my data from variables in a Crystal report? Where I start?
well crystal report can take many things as " DataSource" ranging from object, datatable, dataset etc etc. without looking at the code it is hard to figure out where you are having issue.
basic syntax for crystalreport load datasource is
CrystalDecisions.CrystalReports.Engine.ReportDocument reportDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
reportDoc.Load("your RPT file");
reportDoc.SetDataSource(object)
here instead of object you can use dataset, datatable etc.\
Is this what you were looking for ?
Added
reportDoc.SetDataSource(ds.Tables["YourTableName"])
Also one more thing to note is if you report requires lets say 20 fields they all must be preset in the datatable. or else it will not work. if it has any extra fields in dataset it will just ignore those
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