Reference to data sources

Top  Previous  Next

For reference to data source columns, the following format is used:

 

[DataSource.Column]

 

Source name is separated from column name by a period, for example:

 

[Employees.FirstName]

 

Source name can be compound in case, if we refer to a data source by using a relation. See more details in the "Data" section. For example, this is how you can refer to a related data source column:

 

[Products.Categories.CategoryName]

 

Let us look at the following example of using columns in an expression:

 

[Employees.FirstName] + " " + [Employees.LastName]

 

Here it should be noted that: every column has a definite data type, which is set in the "DataType" property (you can see it in the "Properties" window if to choose data column in the "Data" window beforehand). How a column can be used in an expression depends on its type. For instance, in above mentioned example, both columns - first name and last name - have got a string type and that is why they can be used in such a way. In the following example, we will try to use "Employees.Age" column of numeric type, which will lead to an error:

 

[Employees.FirstName] + " " + [Employees.Age]

 

The error occurs because, you never mix strings with numbers. For this, you need to convert the number into a string:

 

[Employees.FirstName] + " " + [Employees.Age].ToString()

 

In this case, we refer to the "Employees.Age" column as if it is an integer variable. And it is so. We know that all expressions are compiled. All non-standard things (like referring to data columns) from a compiler's point of view are converted into another type, which is understandable to a compiler. So, the last expression will be turned into the following form:

 

(string)(Report.GetColumnValue("Employees.FirstName")) + " " + 

(int)(Report.GetColumnValue("Employees.Age")).ToString()

 

As seen, FastReport changes reference to data columns in the following way:

 

[Employees.FirstName] --> (string)(Report.GetColumnValue("Employees.FirstName"))

[Employees.Age] --> (int)(Report.GetColumnValue("Employees.Age"))

 

That is, we can use data column in an expressions as if it is a variable having a definite type. For example, the following expression will return the first symbol of an employee's name:

 

[Employees.FirstName].Substring(0, 1)