Working with FlexReport > Data Binding in FlexReport > Using Data Table Object as Data Source |
Many applications need to work on the data outside C1FlexReport and load it into DataTable objects. In such cases, you can use DataTable objects as report data sources, avoiding the need to load them again while rendering the report.
This approach is also useful in applications where:
To use a DataTable object as a C1FlexReport data source, simply load the report definition and then assign the DataTable to C1FlexReport.DataSource.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) rep.Load("reportFile", "reportName") ' use DataTable as the data source rep.DataSource.Recordset = dt Private Function GetMyDataTable() As DataTable Dim result As New DataTable() result.Columns.Add("ID", GetType(Integer)) result.Columns.Add("Caption", GetType(String)) result.Rows.Add(1, "Red") result.Rows.Add(2, "Blue") result.Rows.Add(3, "Green") Return result End Function
// load DataTable from cache or from a secure/custom provider DataTable dt = GetMyDataTable(); // load report definition (before setting the data source) rep.Load(@"reportFile", "reportName"); // use DataTable as the data source rep.DataSource.Recordset = dt; private DataTable GetMyDataTable() { DataTable result = new DataTable(); result.Columns.Add("ID", typeof(int)); result.Columns.Add("Caption", typeof(string)); result.Rows.Add(1, "Red"); result.Rows.Add(2, "Blue"); result.Rows.Add(3, "Green"); return result; }