Passing null value to crystal report parameter from csharp

String.empty is passed to a string parameter in crystal report.When we check IsNull(stringparameter) in crystalreport formula it returns false.


if IsNull({?String}) then "Empty parameter" else {?String}---crystal report formula field
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


String.empty is not the same as null. It actually has a reference to an empty string (i.e. "") in it.

You should check for if(stringparameter.Equals(String.empty))

Within Crystal just make your formula:

If IsNull({?String}) OR {?String} = '' then    <- that's 2 single quotes
   "Empty Parameter"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
savithaAuthor Commented:
Thanks for the replies.  The parameters for the crystal report is passed through two applications  1. using classic ASP , 2. using C# .   In ASP , the string can be passed as "null" , but if i pass the string value as "null" in C# it show "Type mismatch" error The formula in the crystal report should not be changed bcoz the crystal reports will be designed by the client.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

I'm confused about what you're asking...

You say the value is passed differently from two applications so I gave you the solution to handle this within Crystal.  You then say you don't want to change the Crystal report so I'm not sure what solution you hope to find.

You can resolve this either by changing the report or by changing the way the values are passed in so they are consistent.  If you are asking whether it is possible to pass a null value in with c#, the answer to that question is no, it is not possible.

The standard approach in this situation would be to pass an empty string consistently because all applications should be able to handle this and Crystal can check for an empty string (using the code I gave you not using the IsNull function).

savithaAuthor Commented:
Thanks frodoman for your responce . As you mentioned i have changed the formula in crystal report.
Pass the parameter with out assigning a value to the object of ParameterDiscreteValue.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.