Posted 8 February 2021, 3:14 pm EST
Hi,
I have create a report on flexreport designer with fields I used from a database, directly set with the designer application, but since I removed this connection on flexreport to replace it on code, it doesn’t work, I get this error with the dataSource object “System.NullReferenceException : object reference not set to an instance of an object”. And i can’t find how to handle this, as the most of samples shows how to load a report yet connected with flexreport designer. I would like to set the connection from an external database in my code and to execute a query here to load after that the template. So my question is what I’m doing wrong, How can I do to create a link on a template created with an external database ?
Here is the code I’ve make so far. Thank you in advance for helping me
private void Window_loaded(object sender, RoutedEventArgs e)
{
string sql = "SELECT * FROM ARCHPOINTS INNER JOIN ARCHRONDES ON ARCHPOINTS.idronde = ARCHRONDES.idarchronde where idarchronde=14 ORDER BY DATEPOINT desc, IDPOINT ASC";
string modelReportPath = @"C:\Users\desou\Desktop\compte-rendu-tournee.flxr";
string nameModelReport = "Compte-rendu de tournée";
C1FlexReport rep = new C1FlexReport();
//load report definition
rep.Load(modelReportPath, nameModelReport);
// initialize DataSource
DataSource ds = rep.DataSource;
ds.Recordset = sql;
ds.DataProvider = DataProvider.OLEDB;
ds.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source =C:\Users\desou\Desktop\rondes.mdb";
ViewerPane.DocumentSource = rep;
}