How to bind datasource to report
Posted: Wed May 28, 2014 8:19 pm
Hello, I am trying to bind a datasource to the report at runtime and cannot seem to get it to work. I have set the connection in the my report template and have verified that I can connect and view data in the designer. However, when I try to add the datasource via code I get no data. Inpsecting the datasource columns gives "Enumeration yielded no results". The query that I am using is the exact same query that is defined in the datasource in the designer. This is the code that I am using
Can someone point out what I am doing incorrectly here? Thank you.
Project code can be found here https://github.com/jamesamuir/reportdatatest.git
Code: Select all
var report = new StiReport();
report.Load(reportPath);
StiConfig.Services.Add(new StiSqlCeAdapterService());
StiConfig.Services.Add(new StiSqlCeDatabase());
StiSqlCeSource DSDynamic = new StiSqlCeSource("SQLCE", "Users", "Users", "SELECT * FROM [Users]", true, false);
report.Dictionary.DataSources["Users"] = DSDynamic;
foreach (StiDataColumn col in DSDynamic)
{
//This does not get hit
DSDynamic.Columns.Add(col.Name, col.Type);
}
report.Dictionary.Synchronize();
report.Compile();
report.Render();
StiPdfExportService pdfExport = new StiPdfExportService();
pdfExport.ExportPdf(report, outputPath);
Project code can be found here https://github.com/jamesamuir/reportdatatest.git