Parameters: How to use them exactly
Parameters: How to use them exactly
Hi,
I have been browsing the forum since the beginning of this morning, trying to find examples on how to implement parameters in the correct way.
What's troubling me is how I'm going to code my project with these ideas.
Sometimes the parameters won't be used and all the data should be visible. On the other hand, there are the parameters depending on the request.
One person would like to view all data from just one place, for example, all persons from one city. And there is another who would like to see how all the men or women in the report.
For this only I would need 2 parameters. But what if 1 parameter does not get set. In the report designer (windows tool) I get an exception because a parameter is not set.
Example:
I have a query: SELECT * FROM persons WHERE Gender = @Gender AND City = @City
Now I would like to see only the persons in a specific city.. But the report requires 2 parameters. I prefer to work with named parameters.
I hope you understand what my intentions are.
Thank you in advance.
I have been browsing the forum since the beginning of this morning, trying to find examples on how to implement parameters in the correct way.
What's troubling me is how I'm going to code my project with these ideas.
Sometimes the parameters won't be used and all the data should be visible. On the other hand, there are the parameters depending on the request.
One person would like to view all data from just one place, for example, all persons from one city. And there is another who would like to see how all the men or women in the report.
For this only I would need 2 parameters. But what if 1 parameter does not get set. In the report designer (windows tool) I get an exception because a parameter is not set.
Example:
I have a query: SELECT * FROM persons WHERE Gender = @Gender AND City = @City
Now I would like to see only the persons in a specific city.. But the report requires 2 parameters. I prefer to work with named parameters.
I hope you understand what my intentions are.
Thank you in advance.
Parameters: How to use them exactly
Hello,
First variant:
You need change your query. For example you can do it with help of variable in query. For example:
You need create MyVariable in report dictionary. Type is string. Before report rendering you need initialize it:
or
Second variant:
You can change query from code before report rendering:
Thank you.
First variant:
You need change your query. For example you can do it with help of variable in query. For example:
Code: Select all
SELECT *
FROM CUSTOMERS
WHERE {MyVariable}
Code: Select all
report.Compile();
report["MyVariable"] = "CUSTOMERID + 123"
report.Show();
Code: Select all
report.Compile();
report["MyVariable"] = "CUSTOMERID = @CustomerID"
report.Show();
You can change query from code before report rendering:
Code: Select all
Stimulsoft.Report.Dictionary.StiSqlSource source = report.Dictionary.DataSources["MySqlSource"] as Stimulsoft.Report.Dictionary.StiSqlSource;
source.SqlCommand = "select * from customers";
report.Render();
Parameters: How to use them exactly
Hi,
Thanks for the reply, but it doesn't answer my question just yet.
What if I have 2 sets of variables, one for each column type.
for example:
Or can I use the whole {variable1} for the entire WHERE clause?
Thanks for the reply, but it doesn't answer my question just yet.
What if I have 2 sets of variables, one for each column type.
for example:
Code: Select all
SELECT * FROM customers
WHERE {variable1} AND {variable2}]
Parameters: How to use them exactly
Hello,
Other variant. Please use the following query, for example:
Create MyVariable in report dictionary. Type is string. Before report rendering you need initialize it:
Thank you.
Other variant. Please use the following query, for example:
Code: Select all
SELECT * FROM CUSTOMERS {MyVariable}
Code: Select all
StringBuilder querry = new StringBuilder();
if (use_param_1 || use_param_2)
{
querry.Append("where ");
if (use_param_1)
{
querry.Append("{variable1}");
}
if (use_param_1 && use_param_2)
{
querry.Append(" and ");
}
if (use_param_2)
{
querry.Append("{variable2}");
}
}
report.Dictionary.Variables["MyVariable"] = querry.ToString();
report.Compile();
report.Show();
-
- Posts: 7
- Joined: Wed Nov 26, 2008 1:40 am
- Location: Philippines
Parameters: How to use them exactly
you can also try this:Brix wrote:Hi,
Thanks for the reply, but it doesn't answer my question just yet.
What if I have 2 sets of variables, one for each column type.
for example:Or can I use the whole {variable1} for the entire WHERE clause?Code: Select all
SELECT * FROM customers WHERE {variable1} AND {variable2}]
Query
Code: Select all
SELECT * FROM Customers
WHERE {vWhereClause}
Create vWhereClause in report dictionary of type String and put the following before report rendering:
Code: Select all
vWhereClause = " Region = ' " + vStringRegion + " ' " + " AND " + " City = ' " + vStringCity + " ' ";
Code: Select all
if (pCondition == 1){
vWhereClause = " Region = ' " + vStringRegion + " ' " + " AND " + " City = ' " + vStringCity + " ' ";
}else{
vWhereClause = " PostalCode = ' " + vStringPostalCode + " ' " + " OR PostalCode IS NULL ";
}
Parameters: How to use them exactly
Hello,
Let us know if you need any additional help.
Thank you.
Let us know if you need any additional help.
Thank you.