Using subreport inside an SSRS table/tablix cell - c#

In my application I have a report with one subreport contained inside a table cell. Within the SubreportProcessing event handler I supply a different set of data foreach instance of the subreport. In VS 2008 this worked okay. However, when I switched over to VS2010 and upgraded the report file format, the behavior changed. All subreport instances in the master table now contain the data that I supplied for the first table row. My code looks like this
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
// _index is a global variable that is reset to zero in the DataBind procedure.
Trip currentTrip = _trips[_index];
e.DataSources.Add(new ReportDataSource("DataSourceName", currentTrip.Items));
_index++;
}
Is this the intended behavior? How can I now supply different datasets for multiple instances of the same subreport inside a table?
Thanks in advance.
Vladislav

After some poking around and tinkering with my code, I found a workaround. The solution is to create a dummy parameter in the subreport, which you then need to bind to a field in the tablix dataset. Any field will do as long as both the subreport parameter and the tablix dataset field are type-compatible. You don't have to do anything with the parameter in the subreport, but now SSRS displays multiple instances of the same subreport, a separate one for each row in the tablix.
Hope this will be helpful for someone else, too.
Vladislav

Related

How to generate freeform rdlc reports with one page per row

Given a data set containing multiple rows, from within a .NET console application I need to generate a report on a single page for each row, sending those pages directly to the printer.
I am attempting to use Microsoft Report for this by attaching it to a data set and placing TextBoxes where I wish. Generating the report and sending it to the printer are not a problem. Unfortunately, the data only seems to be available in aggregates -- First, Sum, Last, Max, etc. I cannot latch the text box to a bare field.
Some poking around here and other sites seems to address this, but only when the data is presented in a table. One post even said without elaboration, "My mistake was using Text Boxes"
Am I using the wrong tool for what I am attempting to accomplish?
I ran into the same problem and managed to solve it. The solution seems a little convoluted to me so don't quote me on the "right" way to do this, but here is what I did:
Make sure you have a Dataset defined for your report.
Add a "Table" control to the report. This seems to be needed in order to iterate the rows in your Dataset.
Delete the header row and two of the default columns from the table so that you are left with a single row with a single column.
Expand the table to the width of your layout and make it as tall as you will need for your "free form" layout.
By default, there is a TextBox inside the table cell. Right-click the empty table cell and choose "delete" to remove that TextBox.
Drag a "Rectangle" control into the empty table cell. It seems to automatically "dock" to the width/height of the table cell.
Now you should be able to drag the fields from your DataSet (TextBoxes, etc) into the Rectangle to produce the desired layout.
Note that I am in the early stages of using this approach so I'm not sure if I am going to hit any walls... but for a basic report that uses TextBoxes and a page break after each "row" it seems to be working ok.
Or you try to use a list.
In the list you can arange textboxes (and other controls) as you want and they will be filled for each record in the recordset.
This work for me. :-)

Using report viewer, how do I pull from two seperate Datasets

I have two datasets I need to pull from, A base that both reports use and then a separate one that only one report pulls from. I get the error
Error 12 The Value expression for the text box ‘Textbox9’ refers to
the field ‘Name’. Report item expressions can only refer to fields
within the current dataset scope or, if inside an aggregate, the
specified dataset scope.
My best guess is I have to associate them with the correct dataset but I have not been able to find any documentation on this.
edit: I am trying to access property files that I created for the fields on the report document.
Can someone please tell me where in the rdlc document I need to code something like name.value, "dataset1" or something similar?
When you create a table in a RLDC, in the Tablix properties (selecting a row or a column) you must associate a DataSet.
After doing that, you have to write in each cell the name of the field (in the dataset) that you will use. You can do that by clicking on the "little table" in the cell, when you put the mouse over it
In images (with Visual Studio 2010)
If you don't see the dataset in the list, you must add it.
For that, click on view menu -> report data.
Then, in the DummyDataSource, click Add Dataset..
And select it from the list, or create a new one instead, in the same form.
If this doesn't work, well I don't know haha
If the two datasets has the same structure, then you could use one just, and in the code assign it to the datasource
I ran into this same error and the only way I could resolve it was by closing and reopening BIDS and then refreshing the fields from the stored procedure (Right click the data set -> Dataset Propoerties -> Query -> Refresh Fields).
Thanks for the troubleshooting tips!
If you are trying to embed the results of one set into a table that is using another data set, have you considered a subreport?
After some careful research and error checking I found that I had to create my base model property file and when I drag the actual data points on to my form I had to associate them with their correct set:
I clicked the value and associated the correct dataset.

Table created dynamically and DataGridView

In my windows form I have to create a table (at runtime) of specified by the user name (in textbox) and then use this table as datasource of DataGridView. Finally, the filled table must be inserted into the database. I tried to solve this problem in two ways:
I have created a DataTable, specified its columns etc. but I couldn't insert the DataTable into the database, even using SqlDataAdapter.Update() - propably I misused DataAdapter. I'm working with C# for 1 week and I don't fully understand the idea of DataSets, TableAdapters etc. So I decided to use SQL commands.
Using ExecuteNonQuery() I've created table in my database, then I recognized, that I have to use magic SqlDataAdapter and I gave up.
I want to manage the content of DataGridView in the same way, as in the case of DataTable added to DataSet using configuration wizard.
I know, that I can skip DataGridView, create list of textboxes, button expanding this list, and function inserting all fields into my table after confirmation button, but my supervisor expects DataGridView.
I can't paste the code here, because I left only copy of source code on company computer. If it will be necessary I will paste here my code tomorrow.
try to use the method either RowValidating or CellValidating of DataGridView
private void dataGridViewEnterTab1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
if (dataGridViewEnterTab1.IsCurrentRowDirty) // Trigger when the row is dirty or has changed
{
string userName = dataGridViewEnterTab1["UserNameCol", e.RowIndex].EditedFormattedValue.ToString();
//...Your SqlDataAdapter or codes
}
}
I hope it will help this idea. :)

LocalReport.SubReportProcessing event is ignoring subsequent DataTables

I have an (rdlc) report which contains a subreport within a table. For each instance of the subreport that is generated the LocalReport.SubreportProcessing event is fired, which is in agreement with the documentation.
However for each of these events, it appears that only the first DataTable assigned is used within the report. I can verify that ReportFactory.ReturnNextDataTable is returning the appropriate DataTable for each row, but it appears the first instance of the DataTable is being repeated multiple times.
I've tried clearing out the report DataSources for each call (using e.DataSources.Clear()) but this makes no difference.
Here is my code:
void AddData(object sender, SubreportProcessingEventArgs e)
{
DataTable merged = ReportFactory.ReturnNextDataTable;
e.DataSources.Add(new ReportDataSource("RATES", merged)); //Subsequent DataTables ignored
}
I can't help feeling I'm going about this fundamentally the wrong way. Any ideas?
I've found the solution :
http://social.msdn.microsoft.com/Forums/es-PY/sqlreportingservices/thread/04f72cea-caea-48c5-82e9-f6b2b962717d
For me, the problem occurs after the migration from Report Viewer 9.0 (2008) to Report Viewer 11.0 (2012).
In continuation to the answer of Stephane CLARISSE here is the extract from the source
After some poking around and tinkering with my code, I found a workaround. The solution is to create a dummy parameter in the subreport, which you then need to bind to a field in the tablix dataset. Any field will do as long as both the subreport parameter and the tablix dataset field are type-compatible. You don't have to do anything with the parameter in the subreport, but now SSRS displays multiple instances of the same subreport, a separate one for each row in the tablix.
This seems to be a bug in SSRS and the workaround is to create a dummy paramaeter with any data type that is passed from the main report. Here is how it solved the problem for me
I added a dummy parameter in the subreport
on the main report, I just passed any field for the dummy parameter that matches with the datatype of the dummy parameter. In my case, it is integer (eventID)

How to filter data in RDLC report?

I am new to RDLC reports in Visual Studio 2010.
I am working on a Website, in this I have used report feature of VS2010. I use ReportViewer to show Report1.rdlc. It is showing it perfectly. Now my requirement is to filter data in report at runtime. I go through this question but not able to understand it's answer.
Because Report1.rdlc is not available in code behind.
Now, how can I filter report's data at runtime?
Surely you assign the dataset to the rdlc report, and in the page of your reportviewer, you would be using an object datasource (and therefor an XSD dataset with datatables), which encapsulates the query.
The query naturally has a where clause, in which you insert your parameters to filter the data by, like:
WHERE (Table.Field = #Param OR #Param = A_Default_Value)
Now add the controls you like to the page before calling the report (drop-down lists, textboxes, etc..), those controls filter the Object datasource, which is mapped to a dataset in the rdlc report, and thus, the report would be filterd upon clicking on a certain button, e.g. Show Report, to refresh the object datasources (databinding them) and re-showing the report in the reportviewer.
You may consider assiging the values of the filtering controls to parameters in the rdlc, so that you may show the parameters of the report in its header upon generating it:
Parameters!ParameterName.Value
Hope that helps you.
How are you getting the data from Server, etc. Are you binding to a datatable result? If so, you can just have your query apply the filter when extracting data to begin with so you don't have to do anything special in the actual report.
Per your feedback, if you are getting a DataTable, then applying a filter should be easy like
DataTable oDT = YourSQLCommandToGetData();
oDT.DefaultView.RowFilter = "SomeColumn = x and OtherColumn = y";
And then run your report. If you want to take it to another level and ENSURE you don't have any unwanted records, you could even do something like
DataTable oNewFilteredResult = oDT.DefaultView.ToTable();
Then, you can assign the NEW table to call the RDLC.

Categories