SSRS: Master-detail report with two datasources - c#

I have two local data sources that I can push into the report. Works no problem. But how do I set up the report? One data source contains a list of employees, and info about them. The other contains a bunch of working hours for each employee.
I would like to use a table for the list of employees, and then have another table for the working hours beneath each employee (with their working hours).
Is this even possible? Do I have to use a Sub-Report? Would I have to merge them into one datasource? =/

As far as I can tell, it is impossible to nest one dataset inside of another one without using a subreport.
This means you need to do one of two things:
Refactor your two datasources into a single datasource. For example, perform a join between the employees and the working hours for each employee. You can then use the grouping properties of the Table object to format the list the way you want it.
If joining the two data sources is not practical, you can use subreports to accomplish what you want. Create a subreport containing the working hours data source and give it a parameter for the current employee. Filter the working hours by this parameter.
In your parent report, you can place the subreport in the list, and pass the employee ID for the current row as a parameter.
Note that there are a few formatting quirks involved with using subreports. I've been able to work around them in most cases, but the preferred method would definitely be number one above.

Adding a new answer to make sure a notification is sent for it.
Using a subreport is the easiest method when it works. You can simply drag and drop a subreport onto a table cell, and it will fill that cell's content area. Right-clicking on the subreport will allow you to edit the parameters for the subreport. Like most values in SSRS, the parameters can be set to expressions which use the fields in the table.
Within the subreport, just filter your results to show only the records associated with the employee who was passed in as a parameter.
The other route you can take is to merge your two datasources using a join. This will give you data something like this:
employee1 time1.1
employee1 time1.2
employee1 time1.3
employee1 time1.4
employee2 time2.1
employee2 time2.2
employee2 time2.3
You can then create a group on the repeated columns (employee in this example), and enable the HideDuplicates property on those columns. The result will look like this:
employee1 time1.1
time1.2
time1.3
time1.4
employee2 time2.1
time2.2
time2.3

To set up multiple datasources...you need to place two separate list objects into the report. Go to the designer, and in the toolbox you can put a new "list" into it. Then, you can do another report. Link that second list to your secondary dataset, which you implement through the secondary datasource.
It's a little bit of a stretch, but the basic idea is that each list object in the report can only be linked to one datasource.

In the report document class there is a property called "Database", which has a collection of tables. You can use "SetDataSource" on each one of those tables, in order to place the separate lists of objects into the report.

Related

RDLC showing additional Rows in a table

I am creating a Report on RDLC. Lets say i have 2 tables in database where im importing data from users and expenses.
Each user can have multiple Expenses. Expenses contain Details and amount just 2 columns that i have to include in the report.
Ive created a stored procedure but its duplicating rows because of having same UserId in expenses. So far im able to achieve this.
See This Picture
What i wanted is that One row with column bulty id and other details with multiple sub rows of expenses.
How can i achieve this. I've tried hide duplicate property in RDLC but its showing duplicate column fields
This is what i wanted to achieve
See image
in this case, I use matrix tool in RDL file.
you should set expenses the ColumnGroup of the matrix
Solved it by doing the Master/Detail Approach. Put 2 tablix in the list. on the first tablix set user details and made a row group so that the values dont repeat and then on the second tablix used the additional data fields.
Then dragged this additional data tablix into the row of first tablix and everything seems to work just fine.
For serial numbering i used Counting distinct values according to my userid

Displaying two attributes in different tables under a single column in a dataGridView

I need to display two different attributes from two different tables (in the same database) under a single column in a single dataGridView.
In my instance, I have Invoice1, AccountName1, Pay_Amount1 attributes in Payment_Details table, and Invoice2, AccountName2, Pay_Amount2 attributes in Receivable_Details table (The reason these same type of attributes are in two different tables instead of one is they are used to display separately in another form). I need to take Invoice1 and Invoice2 and display both under "Invoice" column in a single dataGridView. The same goes to AccountName and Pay_Amount.
Is this possible, if so, how? Any help would be much appreciated.
i suggest two solutions to solve it
s1:
you can join two different tables out of application(for example by creating a view in database) then bind it into grid
s2:
also you can join tables in back end(server side code) and bind its result into grid.
try it and tell me if it worked

How to display information from joined tables in a DataGridView

I would like to write a software which shows database contents in a Forms application. To make it easier to explain, I'll use a shopping list as an example.
I have a number of lists in one table tLists
I have a number of tProductPackages in another table
A list can consist of many productPackages and one productPackage can be in many lists. This m:n relationship is reflected in a separate table named tListProdPacks.
A productPackage contains a product. A product can have several productPackages. In every tProductPackage table entry, there's a foreign key FK_ProductID which references an entry in a table tProducts.
My forms application should navigate through all the lists using a BindingNavigator. In some bound controls, it should display the details of the selected list. This is working fine. (Just bound controls.)
All the list contents (entries in tListProdPacks for the selected tLists element) should be shown in a DataGridView. This is also working fine. Also the details of the productPackages (tProductPackages items i.e. one hop more to the next table) are displayed correctly. In this table he product value is available as ID (FK_ProductID) (foreign key to tProducts).
Is there a way to show the product name (contained only in tProducts) in the DataGridView whose DataSource is tListProdPacks?
(It's easy to display tProductPackages members, as the primary key from tProductPackages is referenced it tListProdPacks and using this ID I can show all other details from tProductPackages by just keep using the same valueMember but use different DisplayMember values for the single DataGridView columns [using dropdown controls in the DGV].)
But when jumping one table further (i.e. when jumping to the tProducts table), this does not work anymore.
I know that I could just create a custom query (join, view) to get exactly what I want, but then I cannot update the database from the dataset anymore.
Does anyone konw how to accomplish that?
(I guess that there's some easy way provided by the framework and I just don't see it, right?)
I'm not sure if I was able to describe what I would like to accomplish good enough. If not, please help me what to provide in addition.
Best regards,
Tom
u can relate the tables using joins if they contain primary key foreign key relation . using joins u can retrieve a single result set containing all the fields which u might need.

how to create a dynamic drop down list in C# with window forms

I'm trying to build a simple inventory program for a friends cellphone store
I want to use C# and access database to store the data
the DB will have 2 main lists:
devices - brand, model, color, price, stock,min_stock
parts - brand, model, description,stock,min_stock
the GUI will use several drop lists
brand will give me : samsung, htc, ect'....
model will give me : I9000,i9100,ect...
the two main problems I have when I try to think how to make it are this:
Each time new brands and models appear
so i need an option to add a new model/brand to the database and then update the drop down list to have them automatically
The drop lists needs to be connected
so if I choose brand A only brands A models will appear in the model drop list
First of all: don't use Access, use SQL Server 2008 Express. But that's only personal taste.
What you need to do to achieve what you want: Create a typed dataset in Visual Studio that contains one table for brands and one for models. Associate the two tables using a relation on the brand column.
Read both tables from the database - first the brands table, then the models table. Otherwise you'll get an error.
Create a master/detail binding for both lists. To do so, drop two BindingSource instances to your form. Associate one of them to the "brands" list and one to the "devices" list. The datasource for the "brands" BindingSource must be set to the brands table in the dataset, the datasource for the other BindingSource must be set to the relation between the two tables. All of this can be one in the designer.
If you have problems setting up the bindings, google for "C# master detail binding dataset".
EDIT
Another option - if the database connection is fast - would be to fill the list of brands from the database and whenever a brand is selected, clear and re-fill the list of models from the database on the fly using the selected brand name.

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.

Categories