RegisterData Questions

pinbotpinbot Texas
edited 6:16PM in FastReport .NET
I'm trying to use RegisterData in FR.Net

I've read and reread all the examples here and cannot seem to get it to work.

In my report Template I have a Database Connection called "Uberbob", under that I have Query Object named "VendorGuideSearch" which is one of the views on my SQL server.

I design my report using the template so I can drag and drop the field names and test with live data. And the report is fine.

Now, in my asp.net program I want to "replace" the query object with a DataTable that is based on the same view but a subset of records.

I get no errors but the report is always how I designed it, not with the data from the DataTable in the application.


Report rep=new Report();
rep.Load(Server.MapPath("SalesWorksheet.frx"));
rep.RegisterData(dt, "VendorGuideSearch"); // dt is my applications DataTable which has a subset of records.
rep.Prepare();

How do I replace the designed query/table with one from my application?

Thanks

Comments

  • edited March 2009
    To do this, register a new data and fix the references to old one. There is no universal way to do this; typically you need to fix the databand's DataSource:

    // use new name!
    rep.RegisterData(dt, "VendorGuideSearchNew");
    (rep.FindObject("Data1") as DataBand).DataSource = rep.GetDataSource("VendorGuideSearchNew");
  • pinbotpinbot Texas
    edited 6:16PM

    Thanks,

    I've done that.

    Now I get 44 rows (the # of rows in my DT) of the first record from the design table.

    Do I have to change EVERY refereced object to point to the new Dataset? One of the objects in my databand is "[VendorGuideSearch.AptName]", do I need to change it to "[VendorGuideSearchNew.AptName]" ?

    That seems strange.

    I would think that this is a common thing. Design a report with some data but at runtime change the source.

    If I try to design with "VendorGuideSearchNew" then I'll never be able to preview in the designer.

  • edited 6:16PM
    Sorry, I forgot about this. Here is correct code that should work:

    // rename old datasource
    rep.GetDataSource("VendorGuideSearch").Name = "VendorGuideSearchOld";

    // register new one, use actual name
    rep.RegisterData(dt, "VendorGuideSearch");

    // correct references
    (rep.FindObject("Data1") as DataBand).DataSource = rep.GetDataSource("VendorGuideSearch");

    I didn't think it's common scenario. I will try to simplify this and let you know if I change something.
  • pinbotpinbot Texas
    edited 6:16PM

    Ok,

    I changed it to match what you have.

    When I Prepare the report, all the Text Objects in the data band now throw exceptions:

    (Text14): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text15): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text15): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text15): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text16): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text17): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text18): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text19): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text20): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text21): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text22): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text23): error CS0103: The name 'VendorGuideSearch' does not exist in the current context
    (Text24): error CS0103: The name 'VendorGuideSearch' does not exist in the current context


    I suppose the "normal" way to create a report is to use parameters but since I already have a dataset showing the results of the user's selections, I just want to pass that to the report. The query in my app is from the same view as the report so I just want to replace the dataset used at design time with the one at runtime.


    The alternative is to replace the design time SQL with the same SQL as the query generated if my application.

    In FR Studio what I'd do is this:

    frx = new TfrxReportClass();
    FileName = Server.MapPath("propsheets.fr3");

    frx.OnBeforePrint += new IfrxReportEventDispatcher_OnBeforePrintEventHandler(Report_OnBeforePrint);

    frx.LoadReportFromFile(FileName);
    frx.EngineOptions.SilentMode = frxSilentMode.simSilent;
    frx.PrintOptions.ShowDialog = false;

    TfrxADOQuery Query = (TfrxADOQuery)frx.FindObject("Query1");

    sql = Session["QuerySQL"].ToString();
    Query.Query = sql;



    Searching this forum, I found the FR.NET equivalent. I tried it and that seems to work. FR will be repeating the already executed SQL query but that should be ok.

    FastReport.Data.TableDataSource tds = (FastReport.Data.TableDataSource) rep.GetDataSource("VendorGuideSearch");
    tds.SelectCommand = sql;



    Thanks for your help.



  • edited 6:16PM
    I've changed the RegisterData behavior. All you need is to call

    rep.RegisterData(dt, "VendorGuideSearch");

    If there was a datasource with "VendorGuideSearch" alias, and if it belongs to a connection, it will be replaced by the new datatable. Note: it works only if "dt" is a DataTable. DataView can't replace the connection's datatable.

    This behavior will be added into v 1.0.184.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.