RdlViewer export problem

456 views
Skip to first unread message

milp...@gmail.com

unread,
Mar 28, 2015, 4:21:09 PM3/28/15
to myfyire...@googlegroups.com
Hello,

I am using Your reporting solution, Majorsilence Reporting. I have a problem with it, so I need your help, if it's not too much trouble. Currently I'm using version 4.7, but I tried with older and newer versions, it's the same.

I've managed to create a report, and show it in the C# application, using RdlViewer component, but I can't export it to HTML, or even PDF. HTML export creates a file, but it says it has no rows, even though the result is shown correctly in a viewer component. PDF causes an exception.

I am using SQLite database, with some simple query, where I show only three columns from the same table. Here is the code I am using:

        private void test()
        {
            RdlViewer rdlViewer = new RdlViewer();

            // Set the connection:
            SQLiteConnection cn = new SQLiteConnection(connection);
            SQLiteCommand cmd = new SQLiteCommand();
            cmd.CommandType = CommandType.Text;


            // Load the report
            rdlViewer.ShowWaitDialog = false;
            rdlViewer.SourceFile = new Uri(path + @"\test.rdl");

            string query = "SELECT Ime, Prezime, Mesto FROM Klijenti";           
            cmd.CommandText = query;
            cmd.Connection = cn;
            DataTable dt = GetTable(cmd);

            rdlViewer.Report.DataSets["Data"].SetData(dt);
            rdlViewer.Rebuild();

            rdlViewer.SaveAs(path + @"\test.html", OutputPresentationType.HTML);

            // Show the report
            frmViewReport showReport = new frmViewReport();
            showReport.Controls.Add(rdlViewer);
            showReport.ShowDialog();                
        }

The GetTable method in the code is the same as in the example on this link: https://github.com/majorsilence/My-FyiReporting/blob/master/Examples/SampleApp2-SetData/SampleApp2-SetData/Form1.cs.

As I said, it is shown correctly, but I get a warning that it is "Unable to connect to datasource 'DS1'.". Also, when I press the button Run Report, report is shown with the message that it has no rows.


Like it was written in a tutorial I read, the same SQL query is used in report and in my code, the database is the same. From Report Designer I can run the report, and it shows the correct result without any warnings. It also exports the report to HTML and PDF without problems.

I tried changing System.Data.SQLite.dll file to the one that ships with your solution, but with no luck. I put RdlViewer.dll, RdlEngine.dll and DataProviders.dll in the same folder where the application is, as well as the System.Data.SQLite.dll. I also tried changing the Data Source location in the report file from absolute to relative, but that doesn't help either.

This is the important part of the RDL file I'm using. Maybe I need to change some settings, I really don't know what seems to be the problem.

<DataSource Name="DS1">
<ConnectionProperties>
<DataProvider>SQLite</DataProvider>
<ConnectString>Data Source=G:\Projects\ReportTest\ReportTest\bin\Debug\test.sqlite</ConnectString>
</ConnectionProperties>
</DataSource>


<DataSet Name="Data">
<Query>
<DataSourceName>DS1</DataSourceName>
<CommandText>SELECT Ime, Prezime, Mesto FROM Klijenti</CommandText>
</Query>
<Fields>
<Field Name="Ime">
<DataField>Ime</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="Prezime">
<DataField>Prezime</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="Mesto">
<DataField>Mesto</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
</DataSet>

I even saw code snippet about exporting (shown below) in one of the topics, but I don't know what to do next:

MemoryStreamGen ms = new MemoryStreamGen();
ProcessReport pr = new ProcessReport(rdlp.Report, ms);
pr.Run(this.ReportParams, OutputPresentationType.PDF);

I hope you can help me with this, because I just can't find the solution to it.

Thanks,
Milan

LeSegatti

unread,
Jun 7, 2017, 9:32:19 AM6/7/17
to myfyireporting, milp...@gmail.com
Hi,

Same problem here, "no rows" printed on report.    I dont know how data refresh..
Message has been deleted

Kernel Klink

unread,
Jun 8, 2017, 8:42:01 AM6/8/17
to myfyireporting, milp...@gmail.com
I can successfully create HTML and PDF reports.  I am hooked up to MySql using MajorSilence v4.11.  In my solution I embed the query in the report and connect via ODBC.  This eliminates any dynamic queries/connection string values at run time.

With that said, I run the following code to output a PDF version.


// Load report
XmlDocument xmlDoc = new XmlDocument();
xmlDoc
.Load(reportFileName);
 
// RDL Parse
RDLParser rdlp = new RDLParser(xmlDoc);
rdlp
.Folder = Path.Combine(applicationPath, Data.Constants.REPORTING_DIRECTORY);
rdlp
.Parse();
this.ProcessErrors(rdlp.Report, "Report Parsing Error");

// Process the report

MemoryStreamGen ms = new MemoryStreamGen();
ProcessReport pr = new ProcessReport(rdlp.Report, ms);
this.ProcessErrors(rdlp.Report, "Report Processing Error");

// Execute the report
pr
.Run(this.ReportParams, OutputPresentationType.PDF);
this.ProcessErrors(rdlp.Report, "Report Running Error");


As for the ProcessErrors method:

/// <summary>
///  Process errors
/// </summary>
/// <param name="rpt">Report</param>
/// <param name="prefix">Prefix to use with errors</param>
private void ProcessErrors(Report rpt, string prefix)
{
   
// Check for severe errors
   
bool isSevere = false;
   
if (rpt.ErrorMaxSeverity > 4) { isSevere = true; }
 
   
StringBuilder sbMsg = new StringBuilder();
   
if (rpt.ErrorItems != null && rpt.ErrorItems.Count > 0)
   
{
        sbMsg
.AppendFormat("{0}{1}", prefix, Environment.NewLine);
 
       
foreach (string item in rpt.ErrorItems)
       
{
            sbMsg
.AppendFormat("{0}\t{1}{2}", isSevere == true ? "Error" : "Warning", item, Environment.NewLine);
       
}
   
}
 
   
if (isSevere == true) { throw new Exception(sbMsg.ToString()); }
   
else if (sbMsg.Length > 0) { Utility.Logging.Write(sbMsg.ToString()); }
}



Hope this helps,

The Kernel
Reply all
Reply to author
Forward
0 new messages