Showing results for 
Search instead for 
Did you mean: 

DataTable Based Report Issues

Former Member
0 Kudos

I am working on a reporting framework with will provide Crystal Reports with data in the form of a DataTable rather than using SQL or any other connection as a DataSource and will display the report in the WPF CrystalReportViewer. It works great, if I have DataRows...However if there is no data being provided, I get overwhelmed with "Field is not known" exceptions.

Below is a quick explanation on how the report is displayed:

  1. Gather Data using OData DataService and populate the DataTable.
  2. Load the report, clear the existing DataSources, and then SetDataSource with the provided DataTable.
  3. Display the Report in the WPF Report Viewer

Like I said, everything works if there are records, but if there is not, I get a lot of "Field is not known exceptions". Due to the requirements of this framework, I cannot define a type that the records will be as it needs to be left open for extensibility. End Users may customize the OData results to provide additional fields.

My first question is:

If there is no data being provided, why does Crystal even try to parse the "Detail" bands?

To get around this issue, I am passing in a parameter called "IsEmpty" = true if there is no data in the DataTable. Then, I use formulas to display my data.


     if({?IsEmpty}) then "" else {Command.Item}

This leads me to my second question:

If the expression is true, why is the false condition being evaluated? I still get that the "Field is not known" for the "Item" field.

Is there a way to NOT evaluate the "Detail" band or formulas if there is no data?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Let me clarify myself:

Its not the fields that are causing the errors, it is the formulas.

I have done the following:

if(isNull({Command.TestType})) then "Null" else if({Command.TestType}="C") Then "Character" else "Not Character"

Even did:

if(1=1) then "Null" else if({Command.TestType}="C") Then "Character" else "Not Character"

And it still tries to parse the else... Whats going on?

Active Contributor
0 Kudos

Instead of using the formulas to read the {?IsEmpty} parameter, you could try suppressing all of the sections if {?IsEmpty} is true.  Basically, you would go to the Section expert and for each section that contains data, click on the formula button to the right of the "Suppress" checkbox (DO NOT check the checkbox!)  Then just type in {?IsEmpty}.  This will suppress the whole section and might alleviate the problem.


Former Member
0 Kudos

Thanks Dell for the response. I tried that as well, didnt work. I think the issue was that the DataTable didnt have columns defined when my results are empty... Still thought null checks would work.

Work Around:

I am building a Default DataTable to use for the report if no data exists. This DataTable will contain all the columns that the report requires. No row data will exist, but as long as long as column headers are specified it works

     protected virtual void InitializeDefaultTable()


          DefaultDataTable = new DataTable();

          foreach (Table table in Database.Tables)


               foreach (DatabaseFieldDefinition field in table.Fields)


                    if (!DefaultDataTable.Columns.Contains(field.Name))


                         DefaultDataTable.Columns.Add(field.Name, GetType(field.ValueType));






     protected virtual Type GetType(FieldValueType fieldType)


          switch (fieldType)


               case FieldValueType.DateField: return typeof(DateTime);

               case FieldValueType.StringField: return typeof(string);

               case FieldValueType.Int16sField: return typeof(Int16);

               case FieldValueType.Int32sField: return typeof(Int32);

               case FieldValueType.BooleanField: return typeof(bool);

               case FieldValueType.NumberField: return typeof(decimal);

               default: return typeof(string);