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:
private void button2_Click(object sender, System.EventArgs e)
{
stiReport1.Load("..\\Variables.mrt");
stiReport1.Compile();
...
Then, assign new values to report variables. You can use the report variable name for this:
...
// Set Variables
stiReport1["Name"] = tbName.Text;
stiReport1["Surname"] = tbSurname.Text;
stiReport1["Email"] = tbEmail.Text;
stiReport1["Address"] = tbAddress.Text;
stiReport1["Sex"] = rbMale.Checked;
stiReport1["BirthDay"] = dtBirthDay.Value;
...
In the end, show the report in the viewer:
...
stiReport1.Show();
}
In the screenshot below you can see the result of the sample code: