网上找的动态读写reportviewer (rdlc)的代码
public MemoryStream GenerateRdlc()
{
XmlDocument sourceDoc = new XmlDocument();
string path = AppDomain.CurrentDomain.BaseDirectory + "job.rdlc";
sourceDoc.Load(path);
XmlNodeList xList=sourceDoc.ChildNodes;
XmlNode xNode = xList.Item(1);
XmlNodeList xx = xNode.ChildNodes;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < xx.Count; i++)
{
if (xx[i].Name.ToLower() == "body")
{
XmlNode xnBody = xx[i];
XmlNodeList xnBodyChildList = xnBody.ChildNodes;
for (int j = 0; j < xnBodyChildList.Count; j++)
{
if (xnBodyChildList[j].Name == "ReportItems")
{
XmlNode xHeader = xnBodyChildList[j];
XmlElement xe = xHeader["Table"];
XmlNodeList xTable = xe.ChildNodes;
for (int k = 0; k < xTable.Count; k++)
{
if (xTable[k].Name.ToLower() == "header")
{
XmlNode xxHeader = xTable[k];
XmlNode xs = xxHeader.ChildNodes.Item(0).ChildNodes.Item(0).ChildNodes.Item(0).ChildNodes.Item(0).ChildNodes.Item(0).ChildNodes.Item(0);
XmlElement xee = xs["Value"];
xee.InnerText = "信息2";
xee.InnerXml = "信息2";
//xee.Value = "信息1";
}
}
}
}
}
}
string path1 = Server.MapPath("~/ddddds.xml");
sourceDoc.Save(path1);
MemoryStream ms = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(typeof(XmlDocument));
serializer.Serialize(ms, sourceDoc);
ms.Position = 0;
return ms;
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=CHENZQ;uid=sa;pwd=luca623;database=pubs");
SqlDataAdapter sda = new SqlDataAdapter("select * from jobs", con);
DataSet ds = new DataSet();
sda.Fill(ds);
ReportDataSource re1 = new ReportDataSource();
this.ReportViewer1.LocalReport.LoadReportDefinition(GenerateRdlc());
this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1",ds.Tables[0]));
this.ReportViewer1.LocalReport.Refresh();
}