Data binding creates a connection between the data source and the UI component, ensuring that updates in the data source are automatically reflected in the UI component, and vice versa. FlexReport supports binding to various data sources to display records. For details on the supported datasources, see DataSources.
The following sections explore how to retrieve data from database and other sources.
A FlexReport definition can include multiple data sources, all accessible through DataSources collection both in .NET and .NET Framework. Each data source in the collection is uniquely identified by its name. These data sources serve as the primary data source, which is referred as the Main data source for a report. The main data source is specified by using DataSourceName property in the report. If the main data source is not specified (DataSourceName is empty or contains a name not found in the DataSources collection), the FlexReport is rendered in unbound mode, containing a single instance of the Detail section.
Follow the steps in below section to access and display data using the OLEDB datasource in .NET and .NET Framework Editions.
C# |
Copy Code
|
---|---|
c1FlexReport1.Load(@"..\..\..\employeereport.flxr", "Employees_Report"); DataSource ds1 = new DataSource(); ds1.Name = c1FlexReport1.DataSourceName; ds1.DataProvider = DataProvider.OLEDB; ds1.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\..\..\C1NWind.mdb;Persist Security Info=False"; ds1.RecordSource = "Employees"; ds1.RecordSourceType = RecordSourceType.TableDirect; c1FlexReport1.DataSources.Add(ds1); c1FlexViewer1.DocumentSource = c1FlexReport1; |
Many applications require processing data outside of C1FlexReport before loading it into DataTable objects. In these scenarios, DataTable objects can serve as report data sources, eliminating the need for reloading during report rendering.
This approach is also useful in applications where:
Perform the following steps to load and render data from a data table:
C# |
Copy Code
|
---|---|
public DataTable GetMyDataTable() { DataTable result = new DataTable(); result.Columns.Add("PiD", typeof(string)); result.Columns.Add("Name", typeof(string)); result.Columns.Add("Supplier", typeof(string)); result.Columns.Add("UnitPrice", typeof(string)); result.Columns.Add("Discontinued", typeof(string)); result.Rows.Add("P001", "Chai", "Bigfoot Breweries", "S100", "False"); result.Rows.Add("P002", "Chang", "Leka Trading", "S200", "True"); result.Rows.Add("P003", "Aniseed", "Karkki Oy", "S130", "False"); result.Rows.Add("P004", "Syrup", "Ma Maison", "S150", "True"); result.Rows.Add("P005", "Konbu", "Tokyo Traders", "S100", "False"); result.Rows.Add("P001", "Chai", "Leka Trading", "S100", "True"); result.Rows.Add("P011", "Chang", "Leka Trading", "S200", "True"); result.Rows.Add("P012", "Aniseed", "Karkki Oy", "S130", "False"); result.Rows.Add("P013", "Syrup", "Ma Maison", "S150", "True"); result.Rows.Add("P014", "Konbu", "Tokyo Traders", "S100", "False"); result.Rows.Add("P015", "Konbu", "Tokyo Traders", "S100", "False"); return result; } |
C# |
Copy Code
|
---|---|
rep.Load(@"..\..\..\productreportqs.flxr", "ProductDataBinding"); DataTable dt = GetMyDataTable(); rep.DataSource.Recordset = dt; flexdataViewer.DocumentSource = rep; |
Stored procedures facilitate a consistent implementation of logic across applications, enhance performance, and abstract the underlying database table details from users. One key advantage of stored procedures is their ability to accept parameters, enabling the database to filter the recordset. This results in a smaller, more manageable data set that is faster and easier for the report to process.
You can populate a report from a stored procedure in the C1FlexReport Wizard. To open the C1FlexReport Wizard, click the New Report button from the Reports tab the C1FlexReportDesigner application. Complete the following steps:
C# |
Copy Code
|
---|---|
flexReport.Load(@"..\..\..\productspreport.flxr", "ProductReportSP"); DataSource ds1 = new DataSource(); ds1.Name = "Mainsp"; ds1.DataProvider = DataProvider.OLEDB; ds1.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;..\..\..\C1NWind.mdb;Persist Security Info=False"; ds1.RecordSource = "[Products by Category]"; ds1.RecordSourceType = RecordSourceType.StoredProcedure; flexReport.DataSources.Add(ds1); flexViewer.DocumentSource = flexReport; |
You can interact with a relational database using SQL statements instead of stored procedures. SQL statements are useful for simple operations where the overhead of invoking a stored procedure is unnecessary. They can be used to query data, insert or update records, delete data, create or modify database objects (such as tables and views), and manage database permissions. Commonly used SQL statements for accessing and modifying data include SELECT, INSERT, DELETE, and UPDATE.
Perform the following steps to load and render data from a database using the SQL statement:
C# |
Copy Code
|
---|---|
ds1.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\..\..\C1NWind.mdb;Persist Security Info=False"; ds1.RecordSource = "SELECT DISTINCT Products.ProductID, Products.ProductName,Categories.CategoryName,Products.UnitPrice FROM (Categories INNER JOIN Products ON Categories.CategoryID = Products.CategoryID)"; ds1.RecordSourceType = RecordSourceType.Text; |