1

I need to dynamically generate columns in an RDLC report. The report displays the breakup of the salary paid to each employee.

Background:
Dynamic column creation is required because every organisation has a unique salary structure and we have given our customers the facility to create their custom salary structures.

I am using:

  • Visual Studio 2015
  • SQL Server 2008 R2 Express
  • Windows 10 Pro x64
  • .Net 4.5.2`

In my opinion, the 3rd option in this post will suit my purpose - Generate columns dynamically in RDLC

What I want to do:

  1. Create a table dynamically in the calling form (I have done this successfully)
  2. Generate an XSD dynamically. The questions I face here is:
    1. How to create an XSD dynamically? I know how to create an XML file. But my questions are:
      1. Where should I write this code?
      2. Where should I store the XSD at runtime so that the RDLC may read from it?
    2. Alongwith the .xsd file, I can see other files with extensions .cs, .Designer.cs, .xsc, .xss. Would I need to make changes in these too?
  3. How do I get the .RDLC file to create the columns and rows dynamically based on this xsd?
  4. Where should I write this code for the .RDLC file?
  5. Where do I store the RDLC file at runtime?
  6. Are the above steps correct or is there another way to do this?

Desired Output Actual Output with dynamic columns in DGV

Error: An error occured during local report processing. The definition of the report " in invalid. The definition of this report is not valid or supported by this version of Reporting Services. The report definition may have been created with a later version of Reporting Services, or contain content that is not well-formed or not valid based on Reporting Services schemas. Details: Deserialization failed: The element 'Fields' in namespace 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition' has incomplete content. List of possible elements expected: 'Field' in namespace 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition'. Line 15, position 9.

Prasad Kamath
  • 182
  • 2
  • 15
  • [Create RDLC report dynamically at run-time from a DataGridView](https://stackoverflow.com/q/40362991/3110834) – Reza Aghaei Feb 25 '18 at 15:44
  • @RezaAghaei - Your example works well for normal DGVs. But I need to add sub totals too. I couldn't find an example anywhere for it. Could you please help further? I have modified the question to include a screenshot of the totals (It is grouped location-wise and then sub-grouped department-wise) – Prasad Kamath Mar 07 '18 at 08:19
  • The linked answer is an example and an idea about what you can do. The role of `DataGridView` in the example is just because of columns. The code of the answer is the t4 template. You need to first create an RDLC report which satisfies your requirement, then modify it to a t4 template like what I created in the linked answer. I believe your answer is too broad and I cannot provide a more specific answer. The linked answer is a good start point for you. – Reza Aghaei Mar 07 '18 at 08:27
  • Rather than dynamic columns, can you instead rotate the data and the columns become rows? – slugster Mar 07 '18 at 08:41
  • @RezaAghaei - Thank you for the quick response. I was in the process of uploading the pics while you responded. Can you have a look at the pics? The upper pic is what I am getting. The lower pic is what I want. After I get the columns dynamically, I will need to make subtotals for them too. – Prasad Kamath Mar 07 '18 at 08:42
  • @slugster - I wish! Unfortunately, that is how the customer wants it. – Prasad Kamath Mar 07 '18 at 08:44
  • @RezaAghaei - I followed [this](https://stackoverflow.com/questions/40362991/create-rdlc-report-dynamically-at-run-time-from-a-datagridview) post of yours. I created a Report Column Model, Report Template and Report Form but I get an error. I tried to google it out but could not get a direct solution. Can you please help? – Prasad Kamath Mar 07 '18 at 18:03
  • Error text is updated in the question – Prasad Kamath Mar 07 '18 at 18:14

0 Answers0