Reference to data sources
Contrary to the FastReport expressions (covered in the "Expressions" section), never use square brackets in script for referring to the data sources. Instead of this, use the GetColumnValue
method of the Report object, which returns the value of the column:
string productName = (string)Report.GetColumnValue("Products.Name");
As seen, you need to indicate the name of the source and its column. The name of the source can be compound in case, if we are referring to the data source by using a relation. Details about relations can be found in the "Data" chapter. For example, you can refer to a column of the related data source in this way:
string categoryName = (string)Report.GetColumnValue("Products.Categories.CategoryName");
For making the work easier, use the "Data" window. From it you can drag data elements into the script, during this FastReport automatically creates a code for referring to the element.
For referring to the data source itself, use the GetDataSource
method of the Report object:
DataSourceBase ds = Report.GetDataSource("Products");
Help on properties and methods of the DataSourceBase
class can be received from the FastReport .NET Class Reference help system. As a rule, this object is used in the script in the following way:
// get a reference to the data source
DataSourceBase ds = Report.GetDataSource("Products");
// initialize it
ds.Init();
// enum all rows
while (ds.HasMoreRows)
{
// get the data column value from the current row
string productName = (string)Report.GetColumnValue("Products.Name");
// do something with it...
// ...
// go next data row
ds.Next();
}