Using Report Variables in Code
Our sample projects and report templates can help you learn the basics of working with our products.This example is outdated, you can check out the many other new examples in this category.This example shows how to use the Report Variables in code. It is necessary to define variables in the report, then the values can be set through code using the variable name. You read more about variables in our documentation.
First, load the report with variables:
Then, assign new values to report variables. You can use the report variable name for this:
In the end, show the report in the viewer:
In the screenshot below you can see the result of the sample code:

First, load the report with variables:
private void button1_Click(object sender, EventArgs e)
{
var report = new StiReport();
report.Load(@"Reports\Variables.mrt");
// Required to prepare the in compilation mode
report.Compile();
...
Then, assign new values to report variables. You can use the report variable name for this:
...
// Set Variables
report["Name"] = textBoxName.Text;
report["Surname"] = textBoxSurname.Text;
report["Email"] = textBoxEmail.Text;
report["Address"] = textBoxAddress.Text;
report["Sex"] = radioButtonMale.Checked;
...
In the end, show the report in the viewer:
...
report.Show();
}In the screenshot below you can see the result of the sample code:
