Breaking News

Wednesday, January 20, 2010

ASP.NET: How to pass NULL value to Crystal Reports

Question: How to pass NULL value, or "no value", to parameters defined in, probably user defined, Crystal Reports, that in turn access the database using watever, sp, query, etc?

This question hanged over my head like a sword - for I was working in production.

This dint really help as I would expect it the usual way it should.! Specially when I found a bug on my production server; this required a hotfix! and well... following is how I worked it around.

Following dint work:
1. Empty string
2. null
3. DBValue.Null

A suggestion, among many, that I got stumbled upon was that, in the crystal reports make update your formula to something like following:

If IsNull({?String}) OR {?String} = '' then  //2 single quotes
   "Empty Parameter"
else
   {?String};

But, we are talking about literally thousands of "user generated" reports; having no access to anything inside the report, except for parameters; something has got to be generic here.

Following, did the trick!
val = (object)(new ParameterDiscreteValue()); //Just instantiate an object of discrete value
reportDocument.SetParameterValue(strParamName, val);//and enjoy!

The reason, that I have boxed it because this loc is right outta my code! Just for someone chasing a stopwatch.

The last, microscopic line, helped me.

Happy null'ing around! (0:

No comments:

Post a Comment

Designed By Published.. Blogger Templates