Note that there are some explanatory texts on larger screens.

plurals
  1. PODataTable Based Crystal Reports Issues
    primarykey
    data
    text
    <p>I'm 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've DataRows...However if there is no data being provided, I get overwhelmed with "Field is not known" exceptions.</p> <p>Below is a quick explanation on how the report is displayed:</p> <ol> <li>Gather Data using OData DataService and populate the DataTable.</li> <li>Load the report, clear the existing DataSources, and then SetDataSource with the provided DataTable.</li> <li>Display the Report in the WPF Report Viewer</li> </ol> <p>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.</p> <p><strong>My first question is:</strong> If there is no data being provided, why does Crystal even try to parse the "Detail" bands?</p> <p>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. i.e.-</p> <pre><code> if({?IsEmpty}) then "" else {Command.Item} </code></pre> <p><strong>This leads me to my second question:</strong> 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.</p> <p>Is there a way to NOT evaluate the "Detail" band or formulas if there is no data?</p> <p><strong>EDIT:</strong></p> <p>This I only get this exception when CR is evaluating the formulas. Is there a way to check if the field is even provided?</p> <p>Exception:</p> <p>This field name is not known. Details: errorKind Error in File QCItemHistoryReportReduced {36B056B1-E4C1-4C1E-A19C-79ACBEE3E3D7}.rpt:</p> <p>Error in formula Format: </p> <pre><code>if(isNull({Command.TestType})) then "Null" else if({Command.TestType}="C") Then "Character" else "Not Character" </code></pre> <p>This field name is not known. Details: errorKind</p> <p><strong>Work Around (Temp Solution):</strong> 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</p> <pre><code> 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); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload