Linq Reporting Engine throws Exception for empty DataTable

I’m trying Linq Reporting Engine and found a problem. If there is no data in the table in the dataset srouce, engine throws an exception.

Unhandled exception. System.IndexOutOfRangeException: There is no row at position 0.

The tag is pretty simple. <<foreach [in Work]>><<[WorkEntityNo]>><>

Datasource is a DataSet and Work is the table name.

How to avoid the exception if there is no data, and simply out empty content on the outcome word???

There must be a way…

@mailzhengli

We suggest you please use ReportingEngine.Options property as shown below. Hope this helps you.

ReportingEngine engine = new ReportingEngine();
engine.Options = ReportBuildOptions.AllowMissingMembers;
DataTable dt = new DataTable();
engine.BuildReport(doc, dt, "Work");

If you still face problem, please attach the following resources here for testing:

  • Your input Word document.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Thanks Tahir,

engine.Options = ReportBuildOptions.AllowMissingMembers; solved the problem. But when I try <<[Work.First().WorkEntityNo]>>, engine throws an exception Unhandled exception. System.InvalidOperationException: The sequence is empty or does not contain a satisfactory element.

Is there a way to only merge a filed in the first row of a table? And if there is no row in the table, the engine will replace the tag with empty string. Is there a tag express can do this?

Thanks

@mailzhengli

Yes, you can achieve your requirement using conditional block of LINQ Reporting. Please read the following article.
Using Conditional Blocks

Moreover, please read the article about template syntax of LINQ Reporting. This will help you to create your template document according to your requirement.