Get Report DataSource and Relations from frx after saved

edited 10:34PM in FastReport .NET
In normal case everything is good,But if user in designer form, add new connection and add new data source that not exists in my first dataset,
after saved ".frx" file, In next time when i load that changed ".frx" file,I am getting this error:
"Table is not connected to the data. Register the data using Report.RegisterData method."
Because i don't know which data source was added by user.
I have to do read ".frx" file as XML, and create datasouce from TableDataSource tag attributes.
Is there a simpler way for Get Report DataSource and Relations details after saved by user and registerd them comfortable in RegisterData method?

Comments

  • Hello!

    You don’t need to parse the .frx file manually as XML immediately after calling report.Load(...); the entire dictionary structure is programmatically accessible via the report.Dictionary object API:

    report.Load(“user_modified.frx”);
    foreach (FastReport.Data.DataConnectionBase conn in report.Dictionary.Connections) { /* connection string */ }
    foreach (FastReport.Data.DataSourceBase ds in report.Dictionary.DataSources) { /* ds.Name, ds.Columns */ }
    foreach (FastReport.Data.Relation rel in report.Dictionary.Relations) { /* Parent/Child tables */ }
    

    To prevent a custom report to which a new SQL connection has been added in the designer from failing with the error “Table is not connected to the data,” register the corresponding connection plugin in the application code once at startup (RegisteredObjects.AddConnection(typeof(...))) and, if necessary, re-read/connect the tables from the list in report.Dictionary.DataSources

This discussion has been closed.