Typed Dataset DataSource for ActiveReports 7 & C1Report
ComponentOne provides two reporting tools namely ActiveReports 7 and C1Report . These components give developers and the end users similar flexibility to connect reports to various data sources. One data source that has been garnering a lot of attention has been the XSD or the Typed Dataset.aspx). This blog article sums up the steps that developers would need to connect C1Report and ActiveReports 7 to a Typed Dataset. The first step that is common to both the reporting components relates to Creating a Typed DataSet or the XSD file that needs to be used as a Datasource for the report. Now that you have Typed Dataset ready, let’s go through the steps on How to Connect ActiveReports 7 and C1 Report to a Typed Dataset (XSD)
Steps to Connect a Typed Dataset to ActiveReports
- Add a new Dataset control to the ActiveReport7 Report Designer in Visual Studio; this will open Add Reference Window.
- In the Add Reference Windows , add a reference to the existing XSD file. 4. Set the name of the DataSet created in previous step in DataSource property of Section Report.
- Set the DataMember property of the report. 7. Database fields should appear in the Bound fields of Report Explorer. Drag Bound Fields from the Report Explorer to the Report designer and design the Report accordingly.
- In the code behind of Section Report, create an instance of TableAdapter and then fill this Adapter with the required table from the DataSet.
private void Report_ReportStart(object sender, EventArgs e)
{
NWINDDataSetTableAdapters.ProductsTableAdapter da = new XSD_dataSource.NWINDDataSetTableAdapters.ProductsTableAdapter();
da.Fill(nwindDataSet1.Products);
}
- Run the Report and View the Report in the ActiveReports Viewer
Steps to Connect a Typed Dataset to C1Report
- Open the C1ReportDesigner application and click the New Report button from the Reports tab to open the C1Report Wizard.
- Set the Data Provider to XML Database and assign the location of the XSD file to Connection String. This will result in the Data source Tab to be populated with Tables from the XSD file.
- Design your report accordingly and save the Report XML to a specified location. 5. Open Visual Studio and add the Report XML to your solution.
- Place a C1PrintPreviewControl on the Windows Form & repeat Steps 1 and 2 as described in the above section Steps to Connect a Typed Dataset to ActiveReports.
Use code provided below to Load the Report XML and Set the Recordset Property of the C1Report to the Typed dataset referenced in Step 6 and view the report in C1PrintPreviewControl.
public void LoadC1Reports() { // load report definition (before setting the data source) c1Report1.Load(GetFilePath("Report.xml"), "Products Report"); // Set the XSD DataSource c1Report1.DataSource.ConnectionString = GetFilePath("NWINDDataSet.xsd"); // Fill the dataset NWINDDataSetTableAdapters.ProductsTableAdapter da = new XSD_dataSource.NWINDDataSetTableAdapters.ProductsTableAdapter(); da.Fill(nwindDataSet1.Products); c1Report1.DataSource.Recordset = nwindDataSet1.Products; c1PrintPreviewControl1.Document = c1Report1; }
Download the attached samples for complete implementation. Download C# Sample Download VB.NET Sample