Showing posts with label declared. Show all posts
Showing posts with label declared. Show all posts

Saturday, February 25, 2012

Parameters and ReportViewer

I have a report in which I am trying to get a parameter to be displayed in a textbox. I have declared a parameter in my .rdlc called UserName and the expression in the textbox is as follows...

=Parameters!UserName.Value

With that said, I have code in the window containing my ReportViewer to set the parameters and run my report as shown below...

string UserName = "test";

List<ReportParameter> paramList = new List<ReportParameter>();

paramList.Add(new ReportParameter(UserName));

this.baseReportViewer.LocalReport.SetParameters(paramList);

this.baseReportViewer.RefreshReport();

With these things in mind, can anyone here provide me with a reason as to why my report on comes up with a message stating "An error occurred during local processing. One or more parameters required to run the report have not been specified." ?

If I remove the parameter and text box and strip out the code pertaining to the paramter in my window, the report runs without error.

Any ideas?

Answered my own question and it was a total noob mistake.

Assuming I have a parameter in my report named "UserName," the code in my form would need to look like the following...(I've highlighted the change in red)

string UserName = "test";

List<ReportParameter> paramList = new List<ReportParameter>();

paramList.Add(new ReportParameter("UserName", UserName));

this.baseReportViewer.LocalReport.SetParameters(paramList);

this.baseReportViewer.RefreshReport();

Parameters - Coalesce!

Hi all,
Just a quick question.
I am calling a stored procedure which has two optional parameters.
Optional meaning they are declared with a default value NULL.
If for some reason and empty string send sent to the procedure will the
internal value of that parameter be NULL or "" ?
Area these the same thing in TSQL ?
Following on from that:
Will the Coalesce Function treat "" & NULL the same?
IE: I need to know if the following will result in 10 if an empty string is
sent to a stored procedure for the 'myParam' parameter..
CREATE PROCEDURE [dbo].[myProcedure]
@.myParam INT = NULL
As
BEGIN
SELECT * FROM myTable
WHERE myTableID = Coalesce(@.myParam,10)
END
Many thanks to those who respond!!!
Adam"Adam Knight" <adam@.pertrain.com.au> wrote in message
news:eNcdq2gyFHA.3860@.TK2MSFTNGP09.phx.gbl...
> Hi all,
> Just a quick question.
> I am calling a stored procedure which has two optional parameters.
> Optional meaning they are declared with a default value NULL.
> If for some reason and empty string send sent to the procedure will the
> internal value of that parameter be NULL or "" ?
An "Empty String" passed in as a parameter is treated as an empty string in
SQL ('')

> Area these the same thing in TSQL ?
A empty string, or zero-length string (ZLS) is not the same thing as NULL.

> Following on from that:
> Will the Coalesce Function treat "" & NULL the same?
COALESCE(value1, value2, ...) returns the first non-NULL value from the list
of values. A common usage of coalesce is something like this:
COALESCE(column, '')
To return a zero-length string in place of a NULL.

> IE: I need to know if the following will result in 10 if an empty string
> is sent to a stored procedure for the 'myParam' parameter..
> CREATE PROCEDURE [dbo].[myProcedure]
> @.myParam INT = NULL
> As
> BEGIN
> SELECT * FROM myTable
> WHERE myTableID = Coalesce(@.myParam,10)
> END
>
An empty string is not a NULL. You shouldn't be passing a 'string' value in
to this procedure anyway - it's an INT parameter. For your example would it
make sense to set the default for @.myParam INT = 10 and get rid of the
COALESCE() function call?

> Many thanks to those who respond!!!
> Adam
>