Can't switch DataTable(DataSet)

edited 8:06AM in FastReport .NET
Hello @all,


I have a strange problem. I create a report from an Excel sheet. But when printing, the data comes from the database. So I want to swap the DataSet. But it does not work. The following error message:
Error BC30451: "Nameplate_i700" is not declared. The object may not be accessible due to the protection level.

But the DataTable is called like that. I get the name of the table from the report and then use it again. Where is the mistake?

Many Thanks

Comments

  • edited 8:06AM
    show the code to reflect your problem
  • edited 8:06AM
    ipong wrote: »
    show the code to reflect your problem
     if (report1.Dictionary.ChildObjects.Count > 0)
                {
                    DataTable dt = null;
                    FastReport.Data.DataConnectionBase con = report1.Dictionary.ChildObjects[0] as FastReport.Data.DataConnectionBase;
                    if (con.Tables.Count > 0)
                    {
                        string name = con.Tables[0].Alias;
                        string sql = con.Tables[0].SelectCommand;
                        string constr = con.ConnectionString;
                        using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(constr))
                        {
                            if (conn != null)
                            {
                                if (conn.State != ConnectionState.Open) conn.Open();
    
                                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, conn))
                                {
                                    dt = new DataTable(name);
                                    dt.Load(cmd.ExecuteReader());
                                }
                            }
                        }
                        if (dt != null)
                        {
                            report1.RegisterData(dt, name); <= this is ok
                            try
                            {
                                //report1.Show();
                                if (report1.Prepare()) report1.ShowPrepared(true, this); <= But here crashes!!!!!
                                if (chkPDF.Checked)
                                {
                                    // create an instance of HTML export filter
                                    FastReport.Export.Pdf.PDFExport export = new FastReport.Export.Pdf.PDFExport();
                                    //export.
                                    // show the export options dialog and do the export
                                    //if (export.ShowDialog())
                                    string file = System.IO.Path.ChangeExtension(report1.FileName, ".PDF");
                                    report1.Export(export, file);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex.InnerException != null)
                                {
                                    ShowRTFMeldung(ex.InnerException.Source, true);
                                    ShowRTFMeldung(ex.InnerException.Message, true);
                                }
                                ShowRTFMeldung(ex.Message, true);
                                ShowRTFMeldung(ex.StackTrace, true);
                            }
                        }
                    }
                }
    
            }
    

    thx

  • edited May 2018
    i have the same problem, reregistering data doesnt work, therefore, do not use the same instance, dispose the old and create new report.

    take a look at http://www.fast-report.com/en/forum/?p=/discussion/14767
    load report => register data => modify report resource string => prepare => failed
  • edited 8:06AM
    ipong wrote: »
    i have the same problem, reregistering data doesnt work, therefore, do not use the same instance, dispose the old and create new report.

    take a look at http://www.fast-report.com/en/forum/?p=/discussion/14767
    load report => register data => modify report resource string => prepare => failed

    What I do not understand, with a real database connection, e.g. MsSQL or something, you can switch the DataSet.
    Only with the CSV connection it does not work
  • edited 8:06AM
    as long as the same report template, using one report instance should be no problem.

    look this code below, first run : data came from embedded connection in frx file and on button1_Click : push datatable to the report, it works well
    public partial class Form1 : Form
    {
        FastReport.Report report = new FastReport.Report();
    
        public Form1()
        {
            InitializeComponent();            
        }
    
        private void Form1_Shown(object sender, EventArgs e)
        {
            // csv file location => d:\Row Datasource.csv
            report.Preview = previewControl1;
            report.Load(@"d:\Untitled.frx");
            report.Prepare();
            report.ShowPrepared();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            FastReport.Data.CsvDataConnection csv = new FastReport.Data.CsvDataConnection();
            csv.Codepage = 1252;
            csv.Separator = ",";
            csv.CsvFile = @"D:\_DOWNLOAD\Row Datasource.csv";
            csv.FieldNamesInFirstString = true;
            csv.RemoveQuotationMarks = true;
            csv.ConvertFieldTypes = true;
    
            csv.CreateAllTables();
            DataTable table = csv.Tables[0].Table;
    
            report.RegisterData(table, "Row Datasource");
            report.Prepare();
            report.ShowPrepared();
        }
    }
    

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.