Using a DataTable Object as a Data Source
Many applications need to work on the data outside of C1Report and load it into DataTable objects. In these cases, you may use these objects as report data sources, avoiding the need to load them again when rendering the report.
This approach is also useful in applications where:
• Security restrictions dictate that connection strings must be kept private and only the data itself may be exposed (not its source).
• The database is not supported by OleDb (the provider used internally by C1Report).
• The data does not come from a database at all. Instead, the DataTable is created and populated using custom code.
To use a DataTable object as a C1Report data source, simply load the report definition and then assign the DataTable to the C1Report Recordset property. For example:
' load DataTable from cache or from a secure/custom provider
Dim dt As DataTable = GetMyDataTable()
' load report definition (before setting the data source)
c1r.Load(reportFile, reportName)
' use DataTable as the data source for the C1Report component
c1r.DataSource.Recordset = dt
• C#
// load DataTable from cache or from a secure/custom provider
DataTable dt = GetMyDataTable();
// load report definition (before setting the data source)
c1r.Load(reportFile, reportName);
// use DataTable as the data source for the C1Report component
c1r.DataSource.Recordset = dt;
|