This is a migrated thread and some comments may be shown as answers.

Exception has been thrown by the target of an invocation Error in Telerik Reporting

5 Answers 1011 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Thi Han
Top achievements
Rank 1
Thi Han asked on 06 Dec 2011, 12:03 PM
Hi All,
I am trying to generate Telerik report with dynamic columns.So I create data table at run time in reporting.So I don't add Datasource in design mode.When I add report to report viewer.This error occurs "Exception has been thrown by the target of an invocation"..
How can I solve this problem.I use the following code in reporting at run time..
private void table1_ItemDataBinding(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.Table processingTable = (sender as Telerik.Reporting.Processing.Table);
            DataTable dtCashBook = new DataTable();
            dtCashBook = control.GetCashBookListForReport();
            processingTable.DataSource = dtCashBook;
            Telerik.Reporting.HtmlTextBox textboxGroup;
            Telerik.Reporting.HtmlTextBox textBoxTable;
            table1.ColumnGroups.Clear();
            table1.Body.Columns.Clear();
            table1.Body.Rows.Clear();
            int i = 0;
            foreach (DataColumn dc in dtCashBook.Columns)
            {
                Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
                table1.ColumnGroups.Add(tableGroupColumn);
                table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Inch(1)));

                textboxGroup = new Telerik.Reporting.HtmlTextBox();
                textboxGroup.Style.BorderColor.Default = Color.Black;
                textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
                textboxGroup.Value = dc.ColumnName.ToString();
                textboxGroup.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
                tableGroupColumn.ReportItem = textboxGroup;

                textBoxTable = new Telerik.Reporting.HtmlTextBox();
                textBoxTable.Style.BorderColor.Default = Color.Black;
                textBoxTable.Style.BorderStyle.Default = BorderType.Solid;
                textBoxTable.Value = "=Fields." + dc.ColumnName;
                textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
                table1.Body.SetCellContent(0, i++, textBoxTable);
                table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });

            }
        }

5 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 06 Dec 2011, 06:04 PM
Hello Thi Han,

The exception you are getting is generic and usually is associated with data retrieving.

control.GetCashBookListForReport(); - Is this method coming from the application that hosts the report? 
If you want to set the dataSource from the App that hosts the report you have to do it outside of the report definition (probably exposing a public property or in some other way), rather than getting from inside the report. 
Please debug your application and make sure that the control.GetCashBookListForReport(); method is working and is retrieving data correctly. If so, please provide us a runnable sample of your project, so we can assist you further.

Note: Threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

Kind regards,
Elian
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Thi Han
Top achievements
Rank 1
answered on 07 Dec 2011, 09:18 AM
Hi
I am sure my GetCashBookListForReport() is working and retrieving data correctly.I'd like to know  to create Telerik reporting at run time another way.Because I want to create columns at run time.
Thank you so much
0
Elian
Telerik team
answered on 07 Dec 2011, 05:10 PM
Hi Thi Han,

Check this forum article. The code provided there is verified and working with the latest version of Telerik Reporting. If it doesn't work for you, there should be some flaw in the logic (data retrieving or something else).

Regards,
Elian
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Thi Han
Top achievements
Rank 1
answered on 08 Dec 2011, 10:03 AM
I already used this code..the error occurs like this

An error has occured while processing Table 'table1'
Missing operator before 'ORDER' operand


my data is retrieved but the error occurs while setting data to 'table1' in reporting..
0
Elian
Telerik team
answered on 09 Dec 2011, 03:59 PM
Hi Thi Han,

Missing operator before 'ORDER' operand
These statements suggests that there is a mistake somewhere in the sorting expressions. Please, check all expressions that could cause the error. If further assistance is needed, send us a runnable project we can inspect.

Regards,
Elian
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
Thi Han
Top achievements
Rank 1
Answers by
Elian
Telerik team
Thi Han
Top achievements
Rank 1
Share this question
or