[]
Before creating a data source, you must first decide what type of data source you need. ActiveReports supports all most common types of data sources, providing a flexible interface for interacting with them.
An example below demonstrates how to create your data source and add it to the report.
private PageReport LoadReport()
{
// Your path to the report
string path = "";
PageReport report = new PageReport(new FileInfo(path));
DataSource dataSource = CreateDataSource();
report.Report.DataSources.Add(dataSource);
return report;
}
private DataSource CreateDataSource()
{
ConnectionProperties connectionProperties = new ConnectionProperties
{
ConnectString = "", // Your connection string to data source
DataProvider = "", // Your data provider name
IntegratedSecurity = true, // or set it to False if you don't need it
};
DataSource dataSource = new DataSource
{
Name = "", // Your data source name
ConnectionProperties = connectionProperties,
};
return dataSource;
}
The CreateDataSource method returns an instance of the DataSource class. This method encapsulates the logic of creating a new data source.
There are two main steps in creating a data source.
1. Creating connection parameters.
ConnectionProperties connectionProperties = new ConnectionProperties
{
ConnectString = "", // Your connection string to data source
DataProvider = "", // Your data provider name
IntegratedSecurity = true, // or set it to False if you don't need it
};
When creating a data source, you can use the following most common data provider names and your own data providers from the configuration file:
2. Creating a data source.
DataSource dataSource = new DataSource
{
Name = "", // Your data source name
ConnectionProperties = connectionProperties,
};
Note that creating your own data source may require additional settings for the report. If you need to modify an existing data source in the report, then use this series of articles.
Data sets are an integral part of almost any report you create in ActiveReports. An example below demonstrates how to create your data set and add it to the report.
private PageReport LoadReport()
{
// Your path to the report
string path = "";
PageReport report = new PageReport(new FileInfo(path));
// Create your own data source or use an existing one
DataSource dataSource = new DataSource();
report.Report.DataSources.Add(dataSource);
DataSet dataSet = CreateDataSet(dataSource);
report.Report.DataSets.Add(dataSet);
return report;
}
private DataSet CreateDataSet(DataSource dataSource)
{
// Your request for data
Query query = new Query
{
Timeout = 30, // Your timeout
CommandText = "", // Your SQL command
DataSourceName = dataSource.Name,
};
// Your data set
DataSet dataSet = new DataSet
{
Query = query,
Name = "", // Your dataset name
};
// Adding fields to the created dataset
CreateFieldsToDataSet(dataSet);
return dataSet;
}
private void CreateFieldsToDataSet(DataSet dataSet)
{
// Your field to add the data set
Field field = new Field
{
DataField = "", // Your name of the field in the query
Name = "", // Your name to use for the field within the report
};
dataSet.Fields.Add(field);
}
In this example, the creation of a data set is divided into the following steps:
Create a data source that will be used to build a data set. See the Create a data source section above for details.
Create a query instance that contains a description of the query that must be executed to retrieve the data.
// Your request for data
Query query = new Query
{
Timeout = 30, // Your timeout
CommandText = "", // Your SQL command
DataSourceName = dataSource.Name,
};
Create a data set instance and pass a previously created query instance into it.
// Your data set
DataSet dataSet = new DataSet
{
Query = query,
Name = "", // Your data set name
};
Add fields to your previously created data set if you need them.
private void CreateFieldsToDataSet(DataSet dataSet)
{
// Your field to add the data set
Field field = new Field
{
DataField = "", // Your name of the field in the query
Name = "", // Your name to use for the field within the report
};
dataSet.Fields.Add(field);
}
type=note
Note: The sample report must contain controls to work with the specified fields in the data set.