Friday, August 8, 2008

Dynamical Chart in SQL Server Reporting Services 2005


Code Snippet
protected void btnViewReport_Click(object sender, EventArgs e)
{
Stream streamingReport;
//The .rdlc file is actually an XML document that structures how the report is to be built.
XmlDocument rdlcXML = new XmlDocument();
try
{
streamingReport = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsumerRaterReports.TransactionsByHour.rdlc");
rdlcXML.Load(streamingReport);
//Change out the Type of the chart in the XML document
XmlNodeList typeNodeList = rdlcXML.GetElementsByTagName("Type");
XmlNode typeNode = typeNodeList[0];

if (uxChartType.Items[uxChartType.SelectedIndex].Text == "")
typeNode.InnerText = "Line";
else
typeNode.InnerText = uxChartType.Items[uxChartType.SelectedIndex].Text;

//Reset the basic report information
ReportViewer1.Reset();
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportDataSource newDataSource = new ReportDataSource();
newDataSource.DataSourceId = "ObjectDataSource1";
newDataSource.Name = "TransactionsByHour_vwGetConsumerStatsByHour";
ReportViewer1.LocalReport.DataSources.Add(newDataSource);
ReportViewer1.LocalReport.ReportPath = string.Empty;
ReportViewer1.LocalReport.LoadReportDefinition(new StringReader(rdlcXML.OuterXml));
ReportViewer1.LocalReport.Refresh();
}
finally
{
streamingReport.Close();
}

... (more code to set datasource and set report to visible)

No comments: