Reportviewer with Subreport - Error processing subreport

Asked

Viewed 944 times

1

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack == true)
    {

        Sipom.DataSets.RelatorioTableAdapters.TodasTabelasTableAdapter Tabela = new
        Sipom.DataSets.RelatorioTableAdapters.TodasTabelasTableAdapter();
        Sipom.DataSets.Relatorio.TodasTabelasDataTable data = Tabela.GetDataTodos();

        ReportViewer1.LocalReport.Refresh();

        ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubDataSource);

    } 

    public void SetSubDataSource(object remetente, SubreportProcessingEventArgs e)
    {

        Sipom.DataSets.RelatorioTableAdapters.TodasTabelasTableAdapter Tabela = new Sipom.DataSets.RelatorioTableAdapters.TodasTabelasTableAdapter();
        Sipom.DataSets.Relatorio.TodasTabelasDataTable data = Tabela.GetDataTodos();
        ReportDataSource RDS1 = new ReportDataSource("DSRespostas", (System.Data.DataTable)data);
        ReportViewer1.LocalReport.DataSources.Add(RDS1); }

With this code I am trying to process the sub-report but the error appears in the following line: ReportViewer1.LocalReport.DataSources.Add(RDS1);

ERROR:

An Exception of type 'System.Invalidoperationexception' occurred in Microsoft.ReportViewer.Webforms.dll but was not handled in user code

Additional information: The viewer control object is in read-only mode

Can anyone help me? I’m not managing to solve this problem. What I want is to load the main report with the sub-report using the tableadpater.

  • Welcome to Stack Overflow, Vasconcelos! While waiting for someone who can answer your question, ask tour to understand why Chun edited his question... for a medal! ;)

1 answer

0


Opa,

In his method SetSubDataSource try adding Datasource using the "e" you received as a parameter, for example, instead of doing:

ReportViewer1.LocalReport.DataSources.Add(RDS1);

Try changing to:

e.DataSources.Add(RDS1);

If it works, mark the answer as valid. Thanks!

  • Hi Andre, thanks for your help,

  • In this way generated the page without errors, but the Subreport is not called, in your knowledge this call is correct? In this case the database tables are not being loaded with the information in the RDS1 object it is null, but when it arrives at the line and.DataSources.Add(RDS1); I can view my table fields, but the information is not loaded, but there is information in the database.

  • See this link for more details than I am using: https://social.msdn.microsoft.com/Forums/pt-BR/d4f378f-0099-40e5-b220-2e77b0062393/reportviewer-subreports?forum=vscsharppt&prof=required

  • You can continue loading your datasource as you were doing, I just indicated the correct way to add it to the subreport, in case only change that line of Reportviewer1.LocalReport.Datasources.Add(RDS1); Even so it doesn’t work?

  • After a series of attempts I was able to recognize the subreport, but I’m having some problems with my Dataset, it is quadrupling the database information. Could you tell me why? Thank you for your help.

  • This link shows more details about my post: https://social.msdn.microsoft.com/Forums/pt-BR/653949cb-8200-4129-9da4-1ba06dc60f8a/porque-o-dataset-com-tableadapter-fourfooting-as-informaes?forum=vscsharppt

  • The information is repeating, because of your Inner Joins. Your Optoesrespostas, Q&A tables are probably tables that have multiple records for each record of the Query table, either 1-N or N-N... ?

  • I am trying to bring the tables Searches, Questions, Options, Results. Searches: Title, Population, Sample, Municipality Questions: Descricaopergunta Obs: In this case we have several searches in which each survey has several questions and each question has some answer options. I need to bring the information in this way, but not duplicate the information. Should I select for each table ? Thanks for all your help.

  • Yes Vanderson, as you have this kind of relationship between the tables, if you do in a SELECT only, will duplicate the information of the "higher" level tables. I recommend you make a SELECT for Searches. There within each result of this SELECT, you must ask another to pick up the Questions, passing in the WHERE clause the Id of the respective survey. Then for each question you make a SELECT of the answer options by going through the WHERE clause the Id of the respective question...and so on.

  • NOTE: Be careful with popular a lot of data on the screen or report, do not forget that by having this hierarchical level many queries will be made, so how lean your query, the better will be the performance.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.