最近做了一些rdlc报表,在添加数据源时想用动态的DataSet。

在<Report>下添加如下 

<DataSources>
<DataSource Name="CommonDataSource">
<ConnectionProperties>
<DataProvider>System.Data.DataSet</DataProvider>
<ConnectString>/* Local Connection */</ConnectString>
</
ConnectionProperties>
</
DataSource>
</DataSources>
<DataSets>
<DataSet Name="CommonDataSet">
<Fields>
<Field Name="FieldName">
<DataField>FieldName</DataField>
<rd:TypeName>System.String</rd:TypeName>
</
Field>
<
/Fields>
<Query>
<DataSourceName>CommonDataSource</DataSourceName>
<CommandText>/* Local Query */</CommandText>
</
Query>
</
DataSet>
</
DataSets>
 
 

 

  
 然后进入编辑器,就会看到添加到的数据源了。
设置自定义纸张问题。
#region [设置打印机纸张]
XmlDocument ReportXml
=new XmlDocument();
ReportXml.Load(ReportPath);
XmlNamespaceManager nsmgr
=new XmlNamespaceManager(ReportXml.NameTable);
nsmgr.AddNamespace(
"ns", "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition");
nsmgr.AddNamespace(
"rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
XmlNode heightXmlNode
= ReportXml.SelectSingleNode("//ns:Page/ns:PageHeight", nsmgr);
XmlNode widthXmlNode
= ReportXml.SelectSingleNode("//ns:Page/ns:PageWidth", nsmgr);
int height =0;
int width =0;
if (heightXmlNode !=null)
height
= Convert.ToInt32(Math.Round(double.Parse(heightXmlNode.InnerText.Replace("cm", "")) *0.39370078740157, 0)) *100;
if (widthXmlNode !=null)
width
= Convert.ToInt32(Math.Round(double.Parse(widthXmlNode.InnerText.Replace("cm", "")) *0.39370078740157, 0)) *100;
reportViewer1.PrinterSettings.DefaultPageSettings.PaperSize
=new PaperSize("自定义报表", width, height);
#endregion
reportViewer1显示报表(WinForm)
 
reportViewer1.ProcessingMode = ProcessingMode.Local;
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.ReportPath
= ReportPath;
reportViewer1.LocalReport.DataSources.Add(
new ReportDataSource("CommonDataSet", new DataSet()));
reportViewer1.RefreshReport();
 
reportViewer1显示报表(WebForm)
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("CommonDataSet", new DataSet()));
ReportViewer1.SetPageSettings(pageSettings);
ReportViewer1.LocalReport.ReportPath
="Report1.rdlc";
posted on 2011-02-25 17:27  BrightMi  阅读(453)  评论(0)    收藏  举报