SSRS 报告 Web 服务中报告参数的日期时间格式问题,而不是报告查看器控件
我想使用 C# 通过 SSRS 报告 Web 服务从报告中读取所有参数。但是我在读取 DateTime 参数时遇到问题。 rdl文件中的参数是英国格式,但在C#中变成了美国格式。
编辑:
我尝试使用下面的代码设置区域性,但它仍然不起作用:
//set it before instantiating ReportingService2010 instance.
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
//set it when reading a date type value
Console.WriteLine("{0} {1} {2}", dateTime.Year, dateTime.Month, dateTime.Day);
Console.WriteLine(dateTime.ToString("yyyy-MM-dd"));
Console.WriteLine(dateTime.ToString("yyyy-MM-dd", new CultureInfo("en-GB", false)));
使用报表查看器控件时,日期格式是正确的。通过报表查看器控件读取参数时,日期值已经正确 (dd/MM/YYYY)。但是,当通过报告 Web 服务读取相同的参数时,相同的值采用另一种格式 (MM/dd/YYYY)。我认为这就是文化设置不起作用的原因。
下面是我的代码:
ReportingService2010 rs = new ReportingService2010();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
string report = "/SampleReports/Employee Sales Summary";
bool forRendering = false;
string historyID = null;
ParameterValue[] values = null;
DataSourceCredentials[] credentials = null;
ItemParameter[] parameters = null;
try
{
parameters = rs.GetItemParameters(report, historyID, forRendering, values, credentials);
if (parameters != null)
{
foreach (ItemParameter rp in parameters)
{
string value = parameter.DefaultValues.FirstOrDefault(); //it becomes US format here
Console.WriteLine("Name: {0}",value);
}
}
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.InnerXml.ToString());
}
ReportingService2010.GetItemParameters 方法
有什么想法吗?
I want to use C# to read all parameters from a report via SSRS reporting web service. But I have a problem when reading a DateTime parameter. The parameter in the rdl file is in British format, but it becomes US format in C#.
Edit:
I tried setting the culture by using the code below, but it still does NOT work:
//set it before instantiating ReportingService2010 instance.
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
//set it when reading a date type value
Console.WriteLine("{0} {1} {2}", dateTime.Year, dateTime.Month, dateTime.Day);
Console.WriteLine(dateTime.ToString("yyyy-MM-dd"));
Console.WriteLine(dateTime.ToString("yyyy-MM-dd", new CultureInfo("en-GB", false)));
The date format is correct when the report viewer control is used. When the parameter is read via the report viewer control, the date value is already correct (dd/MM/YYYY). However, when the same parameter is read via reporting web service, the samevalue is in another format (MM/dd/YYYY). I think this is the reason that setting the culture is not working.
Below is my code:
ReportingService2010 rs = new ReportingService2010();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
string report = "/SampleReports/Employee Sales Summary";
bool forRendering = false;
string historyID = null;
ParameterValue[] values = null;
DataSourceCredentials[] credentials = null;
ItemParameter[] parameters = null;
try
{
parameters = rs.GetItemParameters(report, historyID, forRendering, values, credentials);
if (parameters != null)
{
foreach (ItemParameter rp in parameters)
{
string value = parameter.DefaultValues.FirstOrDefault(); //it becomes US format here
Console.WriteLine("Name: {0}",value);
}
}
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.InnerXml.ToString());
}
ReportingService2010.GetItemParameters Method
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,检查报告本身的语言属性。如果这是正确的,请尝试设置 C# 代码的区域性:
First, check what the language property is in the report itself. If that is correct, try setting the culture of your C# code:
我必须在生成的 ReportingService 类旁边创建一个分部类并重写 GetWebRequest 方法,然后将 Accept-Language 标头添加到 Web 请求中。这是一个示例类:
I have to create a partial class alongside the generated ReportingService class and override the GetWebRequest method, then add an Accept-Language header to the Web request. Here is a sample class: