We have a SSRS report that accepts one date/time input parameter. We have found that the report fails when it is executed from our Silverlight clients with the following error:
"The value provided for the report parameter 'CurrentDate' is not valid for its type."
On further investigation we have found that the report fails when the date value being passed over to the report has a day number greater than 12. e.g. 01/01/2011 is OK. 17/06/2011 will fail. This tells us that the report on the SSRS box must be expecting the date in American format i.e mm/dd/yyyy.
How can I fix this? So far I have tried the following:
I have set the Language property on the report to en-GB. This makes no difference. I have changed the locale in the Silverlight code just before the report is executed e.g.
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
ExecuteReport();
System.Threading.Thread.CurrentThread.CurrentC开发者_C百科ulture = new System.Globalization.CultureInfo("en-GB");
This works but I am not happy with this solution. It seems like a big hack just to get dates accepted on our SSRS reports.
Why is SSRS expecting all date parameters to be in US format? Can I resolve this without jumping through hoops? Please help!
OK I have found one way to get round this. Previously I was passing over a DateTime .NET type. I am now passing over a string value formatted to US date style e.g.
MeetingDate = MyDateVariable.ToString("MM/dd/yyyy");
This works.
It'd also work using the more generic "dash separated" ISO format: yyyy-MM-dd. This format is Regional settings independent. Be aware that simply using the ISO format (yyyyMMdd) it doesn't work.
Regards.
Try:
MyDateVariable.ToString(CultureInfo.InvariantCulture)
精彩评论