RegisterData not working

edited 12:07AM in FastReport .NET
Hi. I'm using a dataset and try to set to report, but not working....
// create report instance
            Report report = new Report();

            // load the existing report
            report.Load(@"..\..\report.frx");            

            // register the dataset
            report.RegisterData(dataset, "Vendas");
            report.GetDataSource("Vendas").Enabled = true;

            // run the report
            report.Show();

            // free resources used by report
            report.Dispose();

This dataset has 10 records, but when I ran the reports, the report show all records. I checked that the query that the report was processed was the query used to design the report.
What I make wrong?

Comments

  • edited 12:07AM
    Try this instead RegisterData:
    string DataSourceName = "your_datasource_name";
    string SQLQuery = "Your new SQL Query";
    
    TableDataSource table = (TableDataSource)report.GetDataSource(DataSourceName);
    table.SelectCommand = SQLQuery;
    

    You can get the query used to design the report and change the sql query.
  • edited 12:07AM
    Servitux wrote: »
    Try this instead RegisterData:
    string DataSourceName = "your_datasource_name";
    string SQLQuery = "Your new SQL Query";
    
    TableDataSource table = (TableDataSource)report.GetDataSource(DataSourceName);
    table.SelectCommand = SQLQuery;
    

    You can get the query used to design the report and change the sql query.

    I'm not happy wiht this solution, because other class is responsible to create the sql command.
    There are other topic with the same problem without answer. The fast report staff don't look to the forum?

  • edited 12:07AM
    Wesley wrote: »
    Wesley wrote: »
    Try this instead RegisterData:
    string DataSourceName = "your_datasource_name";
    string SQLQuery = "Your new SQL Query";
    
    TableDataSource table = (TableDataSource)report.GetDataSource(DataSourceName);
    table.SelectCommand = SQLQuery;
    

    You can get the query used to design the report and change the sql query.

    I'm not happy wiht this solution, because other class is responsible to create the sql command.
    There are other topic with the same problem without answer. The fast report staff don't look to the forum?

    Have you tried to remove your data source from report, and add the new after?

    I think the staff doesn't see this forum...
  • DesignsbyrayDesignsbyray Ohio, USA
    edited 12:07AM
    I know this is hack but you can remove the data sources from the report, in the designer, once you have finished creating it. That way it can't make any database calls you added for testing. As long as the data is registered with the correct name the report engine will still work correctly.

    If you have relations in the report you would need to open the report in a text editor and manually remove the connections leaving the relations intact.

    There is a way to edit the report file source to leave the DataSources usable in the Editor without the actual database connection being present. I can try to elaborate if interested. Keep in mind it falls under the hack category as well.
  • edited June 2017
    I'm not happy wiht this solution, because other class is responsible to create the sql command.
    There are other topic with the same problem without answer. The fast report staff don't look to the forum?


    magento 2 seo suite
  • edited 12:07AM
    Do not use report designer to create datasource.

    All you have to do :

    1. You have blank frx file as a template, open designer.exe , save as blank_report.frx

    2. Create a code in .net application
    using (OleDbConnection cnn = new OleDbConnection(@"........"))
    {
        cnn.Open();
    
        using (OleDbCommand cmd = new OleDbCommand())
        {
            cmd.Connection = cnn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "..........";
    
            using (OleDbDataReader dr = cmd.ExecuteReader())
            {
                using (DataTable dt = new DataTable())
                {
                    dt.Load(dr);
                    dt.TableName = "MainReport";
    
                    FastReport.Report report = new FastReport.Report();
                    report.Load("blank_report.frx")
                    report.RegisterData(dt, dt.TableName);
    
                    //YOU CAN REMOVE AFTER FINISH WITH THE DESIGNER
                    //IN DESIGNER WINDOW, YOU CAN PREVIEW THE REPORT BECAUSE
                    //DATA FROM DATABASE IS REGISTERED
                    report.GetDataSource(dt.TableName).Enabled = true;
                    FastReport.DataBand dataBand = (FastReport.DataBand)report.FindObject("Data1");
                    dataBand.DataSource = report.GetDataSource(dt.TableName);
                    report.Design(true);
    
    
                    //UNCOMMENT AFTER FINISH WITH THE DESIGNER
                    //report.FileName = "My Report";
                    //report.Prepare();
                    //PreviewControl1.AddTab(report, report.FileName);
                    //PreviewControl1.ZoomPageWidth();
                }
            }
        }
    }
    

    3. After finish with report designer, save the frx file
    4. Comment / Uncomment code above
  • edited 12:07AM
  • edited 12:07AM
    Oh... It's finally working!

    Magento 2 Seo
  • How to show fast report in other Form when save finished. Example I design Form1 a report, but I want show Form 2. How to do?? thanks

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.